newLine()和回车符之间的区别(“\ r”") [英] difference between newLine() and carriage return("\r")
本文介绍了newLine()和回车符之间的区别(“\ r”")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
newLine()
和回车(\ r)之间有什么区别?
哪一个最好用?
What is the difference between newLine()
and carriage return ("\r")?
Which one is best to use?
File f = new File(strFileGenLoc);
BufferedWriter bw = new BufferedWriter(new FileWriter(f, false));
rs = stmt.executeQuery("select * from jpdata");
while ( rs.next() )
{
bw.write(rs.getString(1)==null? "":rs.getString(1));
bw.newLine();
}
推荐答案
假设你的意思是:
public static String newLine = System.getProperty("line.separator");
newLine
与环境无关 \ r
不是。
所以 newLine
会给你 \\\\ n
在Windows上,但 \ n
在另一个环境中。
So newLine
will give you \r\n
on windows but \n
on another environment.
但是,您不应该在JTextArea中使用它,并且println在Windows上仅使用 \ n
就可以正常工作。
However, you shouldn't use this in a JTextArea and println will work fine with just \n
on windows.
现在编辑,我已经看到了代码和您的评论
在您的情况下。我认为你应该使用自己的常量 - \\\\ n
In your situation. I think you should use your own constant - \r\n
File f = new File(strFileGenLoc);
BufferedWriter bw = new BufferedWriter(new FileWriter(f, false));
rs = stmt.executeQuery("select * from jpdata");
while ( rs.next() ) {
bw.write(rs.getString(1)==null? "":rs.getString(1));
bw.write("\\r\\n");
}
这篇关于newLine()和回车符之间的区别(“\ r”")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文