这段代码:
PrintWriter output = new PrintWriter(new FileWriter(outputFile, false));
output.println("something\n");
output.println("something else\n");
Run Code Online (Sandbox Code Playgroud)
输出:
something
something else
Run Code Online (Sandbox Code Playgroud)
代替:
something
something else
Run Code Online (Sandbox Code Playgroud)
我尝试使用"\ r \n"而不仅仅是"\n",但它只是不像我想要的那样工作.我该如何解决?
PS我正在使用Windows 7
您可以连接系统的换行符以分隔您的行:
String newLine = System.getProperty("line.separator");
output.println("something" + newLine);
output.println("something else" + newLine);
Run Code Online (Sandbox Code Playgroud)