package test;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import javax.swing.JFileChooser;
public class helloworld {
public static void main(String[] args) throws IOException {
JFileChooser ch = new JFileChooser();
/*ch.showOpenDialog(null);
ch.showSaveDialog(null);*/
BufferedReader br;
BufferedWriter bw;
StringBuffer buffer = new StringBuffer();
int result = ch.showOpenDialog(null);
if(result == JFileChooser.APPROVE_OPTION)
{
File file = ch.getSelectedFile();
br = new BufferedReader(new FileReader(file));
String line;
while((line = br.readLine())!=null)
{
buffer.append(line);
}
System.out.println(buffer);
br.close();
}
result = ch.showSaveDialog(null);
if(result == JFileChooser.APPROVE_OPTION)
{
File file = ch.getSelectedFile();
bw = new BufferedWriter(new FileWriter(file));
bw.write(buffer.toString());
bw.flush();
bw.close();
}
}
}
file_chooser
最新推荐文章于 2023-12-12 08:30:00 发布