设置Java VM line.separator [英] Setting Java VM line.separator
问题描述
有没有人找到一种方法如何在VM启动时指定Java line.separator
属性?我在考虑这样的事情:
Has anybody found a way how to specify the Java line.separator
property on VM startup? I was thinking of something like this:
java -Dline.separator="\n"
但是这并没有将\ n解释为换行符。有什么想法?
But this doesn't interprete the "\n" as linefeed character. Any ideas?
推荐答案
尝试使用 java -Dline.separator = $'\ n'
。应该这样做,至少在bash中。
Try using java -Dline.separator=$'\n'
. That should do the trick, at least in bash.
这是一个测试运行:
aioobe@r60:~/tmp$ cat Test.java
public class Test {
public static void main(String[] args) {
System.out.println("\"" + System.getProperty("line.separator") + "\"");
}
}
aioobe@r60:~/tmp$ javac Test.java && java -Dline.separator=$'\n' Test
"
"
aioobe@r60:~/tmp$
注意:
表达式 $''
使用Bash功能 ANSI-C Quoting 。它会扩展反斜杠转义的字符,因此 $'\ n'
会生成一个换行符(ASCII代码10)字符,用单引号括起来。请参阅Bash手册, 3.1.2.4 ANSI-C引用。
The expression $''
uses the Bash feature ANSI-C Quoting. It expands backslash-escaped characters, thus $'\n'
produces a line feed (ASCII code 10) character, enclosed in single quotes. See Bash manual, section 3.1.2.4 ANSI-C Quoting.
这篇关于设置Java VM line.separator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!