设置 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="
"
但这不会将 "解释为换行符.有什么想法吗?
But this doesn't interprete the " " as linefeed character. Any ideas?
推荐答案
尝试使用 java -Dline.separator=$'
'
.这应该可以解决问题,至少在 bash 中是这样.
Try using java -Dline.separator=$'
'
. 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=$'
' Test
"
"
aioobe@r60:~/tmp$
注意:
表达式$''
使用了 Bash 功能ANSI-C 引用.它扩展反斜杠转义字符,因此 $'
'
产生一个换行(ASCII 代码 10)字符,用单引号括起来.请参阅 Bash 手册,部分 3.1.2.4 ANSI-C 引用.
The expression $''
uses the Bash feature ANSI-C Quoting. It expands backslash-escaped characters, thus $'
'
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屋!