getBytes消耗资源不大,一般就是用这个来解决乱码问题的
顺便给你个方法
public String iso2gb(String str) throws Exception {
if(str==null)return str;
str = new String(str.getBytes("ISO8859_1"), "GBK");
return str;
}
顺便给你个方法
public String iso2gb(String str) throws Exception {
if(str==null)return str;
str = new String(str.getBytes("ISO8859_1"), "GBK");
return str;
}
我的机器上怎么不行,说是Unhandled exception type UnsupportedEncodingException
str的编码方式非"ISO-8859-1",
你可以在异常里面加以判断,
遗憾的是java没有一个直接的方法可以得出一段文字的编码方式,所以可以自己写一段,说白了就是每个编码方式试一试,如果没有上面这种异常出现.ok,编码正确!