平台默认字符编码如何影响跨平台性能 [英] How does the platform default character encoding affect cross platform performance
问题描述
我已经阅读了它的坏主意,使用平台默认字符编码,例如当读取文本文件和将文本导入数组等。你能解释一下如何可以影响跨平台的性能,以及如何克服这个问题?是否有应用于跨平台应用程序的编码?感谢
I have read that its bad idea to use platform default character encoding for example when reading a text file and importing the text into arrays etc. Could you explain how that could affect cross platform performance , and how to get past that problem ? Is there an encoding that should be used for cross-platform applications ? Thanks
推荐答案
这不是关于性能,而是关于显示和阅读正确编码的文本。有多种方法可以解决此问题:
It's not about performance, but about showing and reading properly encoded text. There are a number of ways to cope with the problem:
- 设置JVM选项
-Dfile.encoding = utf -8
- 始终使用重载了字符编码参数的方法。这些是
String
,Reader
,Writer
和更多。
- set a JVM option
-Dfile.encoding=utf-8
- always use the methods overloaded with a character encoding parameter. These are the ones of
String
,Reader
,Writer
and more.
我认为后者是必须的。如果你总是设置jvm选项,它会工作,但如果你忘记设置它在某一点,将在随机的地方出现意想不到的失败。
I think the latter is a must. If you always set the jvm option, it will work, but if you forget to set it at some point, there will be unexpected failures at random places.
问题 - 坚持使用UTF-8。
And the other question - stick to UTF-8.
参见这个问题。
这篇关于平台默认字符编码如何影响跨平台性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!