原理: 先转为unicode,再转
package testPBC;
import java.lang.Character.UnicodeBlock;
public class UTF2GBK {
public static String gbk2utf8(String gbk) {
String l_temp = GBK2Unicode(gbk);
l_temp = unicodeToUtf8(l_temp);
return l_temp;
}
public static String utf82gbk(String utf) {
String l_temp = utf8ToUnicode(utf);
l_temp = Unicode2GBK(l_temp);
return l_temp;
}
/**
*
* @param str
* @return String
*/
public static String GBK2Unicode(String str) {
StringBuffer result = new StringBuffer();
for (int i = 0; i < str.length(); i++) {
char chr1 = (char) str.charAt(i);
if (!isNeedConvert(chr1)) {
result.append(chr1);
continue;
}
result.append("\\u" + Integer.toHexString((int) chr1));