在web 应用开发过程中经常遇到输出某种编码的字符,如从GBK 到iso8859-1 等,如何输出一个某种编码的字符串?
public static String translate(String str) {
String tempStr = "";
try {
tempStr = new String(str.getBytes("ISO-8859-1"), "GBK");
tempStr = tempStr.trim();
} catch (Exception e) {
System.err.println(e.getMessage());
}
return tempStr;
}
public static String translate(String str) {
String tempStr = "";
try {
tempStr = new String(str.getBytes("ISO-8859-1"), "GBK");
tempStr = tempStr.trim();
} catch (Exception e) {
System.err.println(e.getMessage());
}
return tempStr;
}