我正在使用以下函数将字符串写入文件。该字符串用换行符格式化。
例如, text = "sometext\nsomemoretext\nlastword";
我可以在执行以下操作时看到输出文件的换行符:
type outputfile.txt
但是,当我在记事本中打开文本时,看不到换行符。一切都显示在一行中。
为什么会这样。如何确保正确编写文本,以便能够在记事本中正确看到(格式化)。
private static void FlushText(String text, File file)
{
Writer writer = null;
try
{
writer = new BufferedWriter(new FileWriter(file));
writer.write(text);
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
try
{
if (writer != null)
{
writer.close();
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}