//經過swing控件讀取文件get
private static void chooseFile() {
JFileChooser jfc = new JFileChooser();// 初始化文件選擇器
FileNameExtensionFilter filter = new FileNameExtensionFilter("TXT","txt");// 設置文件過濾,TXT爲提示用戶選擇文件類型,txt爲文件過濾後綴
jfc.setFileFilter(filter);// 將文件過濾加載到選擇器中
int returnVal = jfc.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
// 得到打開的文件
File file = jfc.getSelectedFile();
File out = new File(file.getParent() + "\\jiagkun.txt");
try {
InputStreamReader in = new InputStreamReader(
new FileInputStream(file), "UTF-8");
BufferedReader buff = new BufferedReader(in);
BufferedWriter write = new BufferedWriter(new FileWriter(out));
String text = null;
while ((text = buff.readLine()) != null) {
write.write(text + "\n");
}
buff.close();
write.close();
} catch (FileNotFoundException e1) {
} catch (UnsupportedEncodingException e1) {
} catch (IOException e1) {
}
}it