0

I'm desesperatly trying to do return to the line in a text file. But everything is wrote in one line

Here's my code :

addName="saved\\" +name_t.getText() + ".txt";
System.out.println(addName);
File f = new File(addName);
try {
    f.createNewFile();
    FileWriter fw = new FileWriter(f);
    fw.write(pan.getValues());
    fw.close();
} 
catch (IOException e1) {
    e1.printStackTrace();
}

And my getValues function :

public String getValues()
{
    values = "";
    for(int a=0; a<randL.size();a++)
    {
        values = values + "Temperature at " + dateL.get(a) + " is : " + (Double.toString(randL.get(a)) + "°C\n");
    }
    return values;
}

The '\n' doesn't seem to work

Any thoughts ?

Baptiste Arnaud
  • 2,522
  • 3
  • 25
  • 55
  • 7
    http://stackoverflow.com/questions/18549704/java-filewriter-create-a-new-line – Kevin Mee Dec 11 '15 at 17:48
  • For who knows the reason '\n' doesn't work on my PC :p but '\r\n' works ! – Baptiste Arnaud Dec 11 '15 at 17:54
  • @BaptisteArnaud - Java internally uses system propery "line.separator" for the method BufferedWriter.newLine() to write a new line to the file. You can always use System.getProperty("line.separator") to get the correct value for the system irrespective of the OS. – vk239 Dec 11 '15 at 18:03

1 Answers1

2

Try with return and new line:

"\r\n"
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97