Java,默认编码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1128617/
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-08-12 00:03:41  来源:igfitidea点击:

Java, default encoding

javacharacter-encoding

提问by user42155

Possible Duplicate:
What is the default encoding of jvm?

可能的重复:
jvm 的默认编码是什么?

Hello,

你好,

what is the default character encoding in Java, when used to process text data?

当用于处理文本数据时,Java 中的默认字符编码是什么?

I have browsed quite a while, however, I cannot find an answer (or I am not searching properly). I have text data, which was downloaded from web pages. Java was used for this, and the default encoding to process everything. I mean, during the whole process (downloading) no encoding was specified, and I assume there must be some default one. Which one? Thank you.

我已经浏览了很长时间,但是,我找不到答案(或者我没有正确搜索)。我有从网页下载的文本数据。为此使用了 Java,并使用了默认编码来处理所有内容。我的意思是,在整个过程(下载)中没有指定编码,我假设一定有一些默认的。哪一个?谢谢你。

回答by objects

you can specify the default encoding on the command line when the app is started:

您可以在应用程序启动时在命令行上指定默认编码:

java -Dfile.encoding=UTF8 au.com.objects.MyClass

If nothing is specified then the default is got from the underlying OS as AlbertoPL explains above.

如果未指定任何内容,则默认值将从底层操作系统获得,正如 AlbertoPL 上面解释的那样。

回答by Thilo

The default is the derived from the underlying OS. It can be overridden by a system property (file.encoding).

默认值是从底层操作系统派生的。它可以被系统属性(file.encoding)覆盖。

Since both of these are kind of outside of your control, it is probably better to explicitly specify an encoding for all the files your program writes and read. UTF-8 should work in most cases.

由于这两者都在您的控制范围之外,因此最好为您的程序写入和读取的所有文件明确指定编码。UTF-8 应该在大多数情况下工作。