Java: Converting UTF 8 to String

Posted by kujawk on Stack Overflow See other posts from Stack Overflow or by kujawk
Published on 2012-10-02T21:15:55Z Indexed on 2012/10/02 21:37 UTC
Read the original article Hit count: 149

Filed under:
|

When I run the following program:

public static void main(String args[]) throws Exception
{
    byte str[] = {(byte)0xEC, (byte)0x96, (byte)0xB4};
    String s = new String(str, "UTF-8");
}

on Linux and inspect the value of s in jdb, I correctly get:

 s = "ì–´"

on Windows, I incorrectly get:

s = "?"

My byte sequence is a valid UTF-8 character in Korean, why would it be producing two very different results?

© Stack Overflow or respective owner

Related posts about java

Related posts about utf-8