【发布时间】:2011-03-09 23:29:54
【问题描述】:
我是 Java 新手,正在尝试将多行字符串保存到文本文件中。
现在,它确实可以在我的应用程序中使用。就像,如果我从我的应用程序中保存文件,然后从我的应用程序中打开它,它确实会在行之间放置一个空格。但是,如果我从我的应用程序中保存文件,然后在记事本中打开它,它就在一行中。
有没有办法让它在所有程序上显示多行?这是我当前的代码:
public static void saveFile(String contents) {
// Get where the person wants to save the file
JFileChooser fc = new JFileChooser();
int rval = fc.showSaveDialog(fc);
if(rval == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
try {
//File out_file = new File(file);
BufferedWriter out = new BufferedWriter(new FileWriter(file));
out.write(contents);
out.flush();
out.close();
} catch(IOException e) {
messageUtilities.errorMessage("There was an error saving your file. IOException was thrown.", "File Error");
}
}
else {
// Do nothing
System.out.println("The user choose not to save anything");
}
}
【问题讨论】:
标签: java file text save multiline