我是Java新手,尝试将多行字符串保存到文本文件。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");
}
}
什么是一圈? – Daniel 2011-03-09 23:36:47
@丹尼尔我的意思是“应用程序”。 – 2011-03-31 23:18:13