我们在 web 应用开发过程中经常遇到输出某种编码的字符,如 iso8859

我们在 web 应用开发过程中经常遇到输出某种编码的字符,如 iso8859

public String translate(String str){//对传入的str字符串进行转换

String tempStr = "";

try{

tempStr = new String(str.getBytes("ISO-8859-1"), "GBK");//把"ISO-8859-1"转化为“GBK”编码

tempStr = tempStr.trim();

}catch (Exception e){

System.err.println(e.getMessage());

}

return tempStr;

}

相关推荐