I use the following function to write a string to a file. The string is formatted with newline characters.
For instance, text = "sometext\nsomemoretext\nlastword";
I can see the newline characters of the output file when I do this:
type outputfile.txt
However, when I open the text in notepad, I do not see new lines. Everything is displayed on one line.
Why is this happening. How can I make sure that I am writing the text correctly so that I can correctly see (format) in notepad.
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();
}
}
}
source
share