如何在Java应用程序中强制使用Windows行结尾



我有一个Java应用程序,它可以用写入文件

BufferedWriter bw = new BufferedWriter(new FileWriter(outputFile));
bw.write(line + lineTermination);

线路终端定义为:

rn

我在文件中插入了一行奇怪而神秘的空行。

如果我将代码更改为:,我将不会得到额外的行

bw.write(line);
bw.newLine();

但我想强制一个特定的行结束,而不是使用系统属性。客户端特别要求一个行尾字符,有些甚至有|。仅仅使用n是不可行的。

以下是一段缺失行的数据:

"KABE","14/01/11","14:35","14:56","1987","US","SS","CO","MARRIED WITH CHILDREN","","EINE SCHRECKLICH NETTE FAMILIE","","N","10","","12","O'NEILL ED","13","SAGAL KATEY"
"PRO7","14/01/11","14:35","14:55","2001","US","SS","CO","SCRUBS","","SCRUBS DIE ANFAENGER","","C","10","BERNSTEIN ADAM","12","BRAFF ZACH","13","CHALKE SARAH"

感谢您抽出时间:-)

您可以调用

System.setProperty("line.separator", "rn");

以便在代码中设置系统属性。

相关内容

  • 没有找到相关文章

最新更新