问题描述
某些旧代码依赖于平台的默认字符集进行翻译.对于西方世界"中的Windows和Linux安装,我知道这意味着什么.但是考虑到俄罗斯或亚洲平台,我完全不确定其平台的默认字符集是什么(只是UTF-16?).
Some legacy code relies on the platform's default charset for translations. For Windows and Linux installations in the "western world" I know what that means. But thinking about Russian or Asian platforms I am totally unsure what their platform's default charset is (just UTF-16?).
因此,我想知道执行以下代码行会得到什么:
Therefore I would like to know what I would get when executing the following code line:
System.out.println("Default Charset=" + Charset.defaultCharset());
PS:
我不想在这里讨论字符集的问题及其与Unicode的区别.我只想收集什么操作系统会导致什么特定字符集.请仅发布具体值!
I don't want to discuss the problems of charsets and their difference to Unicode here. I just want to collect what operating systems will result in what specific charset. Please post only concrete values!
推荐答案
这是用户特定的设置.在许多现代Linux系统上,它是UTF-8.在Mac上是MacRoman.在Windows上,美国通常是CP1250,在欧洲是CP1252.在中国,您经常会找到简体中文(Big5或GB *).
That's a user specific setting. On many modern Linux systems, it's UTF-8. On Macs, it’s MacRoman. In the US on Windows, it's often CP1250, in Europe it's CP1252. In China, you often find simplified chinese (Big5 or a GB*).
但这是系统默认值,每个用户都可以随时更改.可能的解决方法是:在使用系统属性file.encoding
But that’s the system default, which each user can change at any time. Which is probably the solution: Set the encoding when you start your app using the system property file.encoding
查看此答案方法.我建议将其放入一个小的脚本中,该脚本可以启动您的应用程序,因此不会污染用户的默认设置.
See this answer how to do that. I suggest to put this into a small script which starts your app, so the user default isn't tainted.
这篇关于平台在不同平台上的默认字符集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!