为什么 System.getProperty(“line.seperator”) 返回 null?
正如标题所问,为什么 System.getProperty("line.seperator") 返回 null。
环顾四周,我发现不应该。
运行此代码显示它似乎被设置为带有分隔符的行已损坏:
class Test {
public static void main( String[] args ) {
System.out.println(System.getProperties());
}
}
$ java Test
{java.runtime.name=Java(TM) SE Runtime Environment, sun.boot.library.path=/usr/lib/jvm/java-6-sun-1.6.0.24/jre/lib/i386, java.vm.version=19.1-b02, java.vm.vendor=Sun Microsystems Inc., java.vendor.url=http://java.sun.com/, path.separator=:, java.vm.name=Java HotSpot(TM) Server VM, file.encoding.pkg=sun.io, sun.java.launcher=SUN_STANDARD, user.country=GB, sun.os.patch.level=unknown, java.vm.specification.name=Java Virtual Machine Specification, user.dir=/home/niko, java.runtime.version=1.6.0_24-b07, java.awt.graphicsenv=sun.awt.X11GraphicsEnvironment, java.endorsed.dirs=/usr/lib/jvm/java-6-sun-1.6.0.24/jre/lib/endorsed, os.arch=i386, java.io.tmpdir=/tmp, line.separator=
, java.vm.specification.vendor=Sun Microsystems Inc., os.name=Linux, (And so on...)
但是,当尝试在代码中获取此代码时,我得到 null:
class Test{
public static void main( String[] args ) {
System.out.println("This is not " + System.getProperty("line.seperator") + "Broken");
}
}
$ java Test
This is not nullBroken
我正在使用 Ubuntu 10.10 和 Java(内部版本 1.6.0_24-b07)。
谢谢
Exactly as the title asks, why is System.getProperty("line.seperator") returning null.
From looking around I gather that it shouldn't.
Running this code shows that it seems to be set as the line with the separator is broken:
class Test {
public static void main( String[] args ) {
System.out.println(System.getProperties());
}
}
$ java Test
{java.runtime.name=Java(TM) SE Runtime Environment, sun.boot.library.path=/usr/lib/jvm/java-6-sun-1.6.0.24/jre/lib/i386, java.vm.version=19.1-b02, java.vm.vendor=Sun Microsystems Inc., java.vendor.url=http://java.sun.com/, path.separator=:, java.vm.name=Java HotSpot(TM) Server VM, file.encoding.pkg=sun.io, sun.java.launcher=SUN_STANDARD, user.country=GB, sun.os.patch.level=unknown, java.vm.specification.name=Java Virtual Machine Specification, user.dir=/home/niko, java.runtime.version=1.6.0_24-b07, java.awt.graphicsenv=sun.awt.X11GraphicsEnvironment, java.endorsed.dirs=/usr/lib/jvm/java-6-sun-1.6.0.24/jre/lib/endorsed, os.arch=i386, java.io.tmpdir=/tmp, line.separator=
, java.vm.specification.vendor=Sun Microsystems Inc., os.name=Linux, (And so on...)
However when trying to get this in code I get null:
class Test{
public static void main( String[] args ) {
System.out.println("This is not " + System.getProperty("line.seperator") + "Broken");
}
}
$ java Test
This is not nullBroken
I am using Ubuntu 10.10 and Java (build 1.6.0_24-b07).
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您拼错了
line.separator
。You've misspelt
line.separator
.