[摘要]Save事件处理器调用的方法saveFile()。可将其放在openFile()方法之后。这个方法在保存时也将文件名写到状态栏。 // Save current file;...
Save事件处理器调用的方法saveFile()。可将其放在openFile()方法之后。这个方法在保存时也将文件名写到状态栏。
// Save current file; handle not yet having a filename; report to statusBar.
boolean saveFile() {
// Handle the case where we don't have a file name yet.
if (currFileName == null) {
return saveAsFile();
}
try
{
// Open a file of the current name.
File file = new File (currFileName);
// Create an output writer that will write to that file.
// FileWriter handles international characters encoding conversions.
FileWriter out = new FileWriter(file);
String text = jTextArea1.getText();
out.write(text);
out.close();
this.dirty = false;
// Display the name of the saved directory+file in the statusBar.
statusBar.setText("Saved to " + currFileName);
return true;
}
catch (IOException e) {
statusBar.setText("Error saving "+currFileName);
}
return false;
}
创建没有当前文件名时,从saveFile()方法中调用的saveAsFile()方法。它也可以从File
关键词:JBuilder 9 开发一个文本编辑器