平台的默认字符集在不同的平台

平台的默认字符集在不同的平台

本文介绍了Java:平台的默认字符集在不同的平台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

某些旧版程式码依赖于平台的预设翻译字元集。对于在西方世界中的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());

编辑
我不想讨论问题的字符集和他们的区别在这里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

a href =http://stackoverflow.com/a/623036/34088>查看此答案如何做到这一点。我建议把它放入一个小脚本启动你的应用程序,所以用户默认不被污染。

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.

这篇关于Java:平台的默认字符集在不同的平台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 01:03