Java字符编码为HTML ISO-8859-1

时间:2017-11-07 12:01:41

标签: java character-encoding

我有一个包含值-110(和其他负值)的byte []。当我将其转换为字符串时,我需要它显示'(右单引号)。目前,我收到一个问号(?)

'与this page中提到的特殊ASCII字符#146对齐,但我现在不知道如何输入-110或146(-110 + 256)并成为'值。我也有任何建议。非常感谢。

byte[] b = {-110,84};
System.out.println(new String(b, Charset.forName("Windows-1252"))); //Displays ?T . The desired output should be ’T
System.out.println(new String(b, Charset.forName("UTF-8"))); //Displays ?T . The desired output should be ’T
System.out.println(new String(b, Charset.forName("ISO-8859-1"))); //Displays ?T . The desired output should be ’T

1 个答案:

答案 0 :(得分:1)

感谢John Skeet在回复中指出的回复,Java程序需要识别输入数据Windows-1252并且Windows命令行也没有设置到代码页。

通过运行

命令行代码页设置为Windows-1252
chcp 1252

启动Java程序以使用Windows-1252作为默认值,通过添加以下参数来完成

-Dfile.encoding="Windows-1252"
相关问题