Chris
Chris

Reputation: 21

Java character encoding to HTML ISO-8859-1

I have a byte[] containing the value -110 (and other negative values). When I convert it to string I need it to display a ’ (right single quote). Currently, I am getting a question mark (?)

The ’ aligns to the special ASCII character #146 mentioned in this page but I am now stuck as to how I can input -110 or 146 (-110+256) and be a ’ value. I have also trued Any advice would be greatly appreciated.

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

Upvotes: 1

Views: 654

Answers (1)

Chris
Chris

Reputation: 21

Thanks for the responses as John Skeet points out in his reply, the Java program needed to recognize the input data Windows-1252 and the Windows command line wasn't set to the code page either.

Setting the command line codepage to Windows-1252 was done by running

chcp 1252

Starting the Java program to use Windows-1252 as the default was done by adding the following parameter

-Dfile.encoding="Windows-1252"

Upvotes: 1

Related Questions