javacharacter-encodinggb2312

character encoding issue - GB2312


I am displaying simplified chines character retrieved from database using the below code snippet but it is displaying junk character

String text="×°ÏäʱÇëÅÄÕÕ";  // retrieved from database 
String result=new String(text.getBytes("utf-8"),"GB2312");

Actual output is : �掳�盲�卤�毛����

Expected Output is : 装箱时请拍照

please help


Solution

  • A string always should have the correct characters. Only during conversion to a byte stream the encoding comes into play.

    So when text is what you got from the DB then you have the problem already in fetching the string from the DB.