读书人

字符集的互相转换

发布时间: 2012-07-01 13:15:00 作者: rapoo

字符集的相互转换

public class Util {
/**
* 字符集转换ISO_GBK
* @param tmp
* @return
*/
public static String swithCharISO_GBK(String tmp){
String str=null;
try {
str = new String(tmp.getBytes("iso-8859-1"),"GBK");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return str;
}

/**
* 字符集转换GBK_ISO
* @param tmp
* @return
*/
public static String swithCharGBK_ISO(String tmp){
String str=null;
try {
str = new String(tmp.getBytes("GBK"),"iso-8859-1");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return str;
}


}

读书人网 >Web前端

热点推荐