简体   繁体   English

Windows-1252编码 - 显示不正确的字符

[英]Windows-1252 encoding - incorrect characters displayed

I have a buffer with chars encoded in Windows-1252. 我有一个带有在Windows-1252中编码的字符的缓冲区。 However when I create a new String with appropriate encoding, instead of expected result I've get quite often interrogation marks, ex. 但是,当我使用适当的编码创建一个新的String时,而不是预期的结果,我经常会得到询问标记,例如。

byte[] tmps = new byte[] {(byte) 0xfb};
System.out.println (new String (tmps,0,1,"Windows-1252" ));

As result the system should display "u" char with "^" above it. 结果,系统应显示“u”字符,其上方带有“^”。 Instead it displays "?". 而是显示“?”。

Any idea? 任何想法?

First of all Windows-1252 is a supported encoding: 首先,Windows-1252 受支持的编码:

I think that the most likely problem here is on the output side. 我认为这里最可能出现的问题是输出端。 Specifically, Java may think that your locale's default charset is ASCII or something that doesn't support that codepoint. 具体来说,Java可能会认为您的语言环境的默认字符集是ASCII或不支持该代码点的内容。

One way to eliminate Windows-1252 as the cause of the problem is to write the equivalent string using a Unicode escape; 消除Windows-1252作为问题原因的一种方法是使用Unicode转义编写等效字符串; eg 例如

    System.out.println("\u00fb");

I've already found this. 我已经发现了这个。

Menu Run/Run configurations/ next Java Application and your own app name/tab common/ next encoding set to UTF-8 菜单运行/运行配置/下一个Java应用程序和您自己的应用程序名称/选项卡常用/下一个编码设置为UTF-8

And since now both windows 1250 and 1252 chars seems to be displayed ok. 从现在开始,Windows 1250和1252个字符似乎都显示正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM