gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 19:35:19 25 4
gpt4 key购买 nike

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

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

行终止定义为:

\r\n

我的文件中插入了奇怪的、神秘的空行。

如果我将代码更改为:

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", "\r\n");

为了在代码中设置系统属性。

关于java - 如何在 Java 应用程序中强制使用 Windows 行结尾?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6128174/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com