Swing中用JFileChooser选择路径保存文件
String ss = this.mailEditor.getText();
JFileChooser jfc = new javax.swing.JFileChooser();
if(JFileChooser.APPROVE_OPTION == jfc.showSaveDialog(this)) {
File saveFile = jfc.getSelectedFile();
try {
if(!saveFile.exists()){
saveFile.createNewFile();
}
BufferedWriter bw = new BufferedWriter(new FileWriter(saveFile));
bw.write(ss);
bw.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
本文介绍如何使用Swing中的JFileChooser组件来选择文件路径并保存文本内容。通过创建JFileChooser实例,展示文件保存对话框,并将文本编辑器中的内容写入选定的文件。

被折叠的 条评论
为什么被折叠?



