看不懂不要紧,看案例后的解析
public 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;
}
如果你只想得到某个字符串的指定编码格式的字节数组,需要注意在获取字节数组的语句要写到捕获异常的语句中,Eg:try catch 或者在方法上抛出异常 Eg:throws UnsupportedEncodingException
大功告成,又get到了一个知识有木有。 公众号:知识浅谈