如何在创建的.csv文件中转到新行。我只能使用“;”
进入下一个单元格File temp = new File("results11234.csv");
FileWriter writer = new FileWriter(temp);
for (int i = 0; i < dirs2.size(); i++) {
try {
writer.append(dirs.get(i)+ ';');
writer.append((Integer.toString(dirs2.get(i)) + ';'));
} catch (Exception e) {
e.printStackTrace();
} finally {
}
}
writer.flush();
writer.close();
答案 0 :(得分:1)
您可以添加换行符:
writer.append("\n"); // for unix
writer.append("\r\n"); // for windows
如果您想独立于平台,可以执行以下操作:
String lineSep = System.getProperty("line.separator");
...
writer.append(lineSep);
或者您使用BufferedWriter(我认为最好的方式):
BufferedWriter writer = new BufferedWriter(new FileWriter(temp));
...
writer.newLine();
我希望,这有帮助