0
我正在desesperatly試圖做回到文本文件中的行。但一切都在一行中寫道試圖寫一個到文本文件返回行 n「
這裏是我的代碼:
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();
}
而且我的GetValues函數:
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;
}
的 '\ n' 似乎並沒有工作
任何想法?
http://stackoverflow.com/questions/18549704/java-filewriter-create-a-new-line –
誰知道原因 '\ n'在我的電腦上不起作用:p但'\ r \ n'正常工作! –
@BaptisteArnaud - Java在內部使用系統propery「line.separator」來爲BufferedWriter.newLine()方法寫入一個新行。無論操作系統如何,您都可以使用System.getProperty(「line.separator」)獲取系統的正確值。 – vk239