【发布时间】:2014-10-08 23:16:25
【问题描述】:
我正在开发记事本项目,想知道如何保存文件.txt,我的问题是,我保持文件打开JFileChooser,在选择了要保存的本地后,但如果再次保存将再次打开JFileChoose。我要保存。不另存为。
JFileChooser fc = new JFileChooser();
int resp = fc.showSaveDialog(fc);
if (resp == JFileChooser.APPROVE_OPTION) {
PrintStream fileOut = null;
try {
File file = fc.getSelectedFile();
fileOut = new PrintStream(file);
fileOut.print(txtArea.getText());
} catch (FileNotFoundException ex) {
Logger.getLogger(frmNotePad.class.getName()).log(Level.SEVERE, null, ex);
} finally {
fileOut.close();
}
【问题讨论】:
标签: java save jfilechooser notepad