public String changeCharset(String str, String oldCharset, String newCharset)
throws UnsupportedEncodingException {
if (str != null) {
// 用源字符编码解码字符串
byte[] bs = str.getBytes(oldCharset); //
return new String(bs, newCharset);
}
return null;
}
throws UnsupportedEncodingException {
if (str != null) {
// 用源字符编码解码字符串
byte[] bs = str.getBytes(oldCharset); //
return new String(bs, newCharset);
}
return null;
}

本文介绍了一个简单的字符集转换方法,该方法使用Java实现,能够将输入的字符串从一种字符集编码转换为另一种字符集编码。如果输入的字符串不为空,则会先将其按照旧的字符集进行解码得到字节数组,再将该字节数组按照新的字符集进行编码,最终返回转换后的字符串。

被折叠的 条评论
为什么被折叠?



