java 如何在命令行上设置JVM字符集?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10890578/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 02:59:41  来源:igfitidea点击:

How to set the JVM charset on the command line?

javacharacter-encodingjvm

提问by One Two Three

What's the command to set the JVM's character set?

设置JVM字符集的命令是什么?

(Also, what's the command to view the current JVM's character set, so I know how to reset it back to default after I'm done)

(另外,查看当前JVM字符集的命令是什么,所以我知道如何在完成后将其重置为默认值)

Thanks,

谢谢,

回答by Nathan Feger

java strings are always utf-16 internally (javadoc link), but you can use -Dfile.encoding=UTF-8to facilitate reading files with a default charset.

java 字符串在内部始终是 utf-16(javadoc 链接),但您可以使用-Dfile.encoding=UTF-8默认字符集方便读取文件。

Just ensure java has access to that fileset when you set it or it won't start.

只要确保 java 可以在您设置它时访问该文件集,否则它将无法启动。

回答by Matthew Cline

java.nio.charset.Charset.defaultCharset()Will get you the JVM's default charset.

java.nio.charset.Charset.defaultCharset()将为您提供 JVM 的默认字符集。