如何在 Java 应用程序中强制使用 Windows 行结尾? [英] How do I force Windows line endings in Java app?
本文介绍了如何在 Java 应用程序中强制使用 Windows 行结尾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个写入文件的 Java 应用程序:
I have a Java app that writes to a file with:
BufferedWriter bw = new BufferedWriter(new FileWriter(outputFile));
bw.write(line + lineTermination);
行终止定义为:
我的文件中插入了奇怪而神秘的空行.
I get the odd, mysterious blank line inserted into my file.
如果我将代码更改为:
bw.write(line);
bw.newLine();
但我想强制一个特定的行结束,而不是使用系统属性.客户特别要求行结束字符 - 有些甚至有 |.仅使用 不是可行的解决方案.
But I want to force a specific line ending, not use System property. Clients specifically request a line ending character - some even have |. Its not a viable fix to just use .
这是缺失行的数据片段:
Here is an snippet of the data with missing line:
"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", "
");
为了在代码中设置系统属性.
in order to set the system property inside your code.
这篇关于如何在 Java 应用程序中强制使用 Windows 行结尾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文