// shall I write some keywords here to boost search engine ranking?

Friday, November 14, 2008

Java: convert UCS2 to UTF-8

While convert UCS2 into UTF-8, I hit UnsupportedEncodingException. So I use UTF-16 instead and it work well (at least till the time I write this post):


public String ucs2ToUTF8(byte[] ucs2Bytes) throws UnsupportedEncodingException{

String unicode = new String(ucs2Bytes, "UTF-16");

String utf8 = new String(unicode.getBytes("UTF-8"), "Cp1252");

return utf8;
}

1 comment:

Anonymous said...

Thanks. The UTF16 solved my issue as well, but not the UTF8.