我们在web应用开发过程中经常遇到输出某种编码的字符,如iso-8859-1等,如何输出一个某种编码的字符串?

字符集中文乱码浏览:403收藏:0
答案:
public String translate(String str) {
try {
return new String(str.getBytes("ISO-8859-1"), "GBK").trim();
} catch (Exception e) {
System.err.println(e.getMessage());
throw new RuntimeException(e);
}
}