Y
yaliguo
Unregistered / Unconfirmed
GUEST, unregistred user!
我在使用以下两个函数时发现一些问题,当utf-8编码的字符转换成Unicode后,再转换成utf-8时,若中文字符数为偶数则没有问题,若为奇数则最后一个字会出现乱码,哪位大侠帮忙看看,多谢!
public final static String Unicode2UTF8(String value) {
try {
return new String(value.getBytes(), "UTF-8"
} catch (UnsupportedEncodingException ex) {
ex.printStackTrace();
return ex.getMessage();
}
}
public final static String UTF82Unicode(String value) {
try {
return new String(value.getBytes("UTF-8");
} catch (UnsupportedEncodingException ex) {
ex.printStackTrace();
return ex.getMessage();
}
}
public final static String Unicode2UTF8(String value) {
try {
return new String(value.getBytes(), "UTF-8"
} catch (UnsupportedEncodingException ex) {
ex.printStackTrace();
return ex.getMessage();
}
}
public final static String UTF82Unicode(String value) {
try {
return new String(value.getBytes("UTF-8");
} catch (UnsupportedEncodingException ex) {
ex.printStackTrace();
return ex.getMessage();
}
}