UTF-8编码转换为ISO-9959-1、ISO-9959-1编码转换为UTF-8

UTF-8编码转换为ISO-9959-1

public static String utf8ToIso88591(String str) {
if (str == null) {
return str;
}

try {
return new String(str.getBytes("UTF-8"), "ISO-8859-1");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e.getMessage(), e);
}
}

ISO-9959-1编码转换为UTF-8

public static String iso88591ToUtf8(String str) {
if (str == null) {
return str;
}

try {
return new String(str.getBytes("ISO-8859-1"), "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e.getMessage(), e);
}
}

 

posted @ 2021-08-10 16:29  游走人间的蒲公英  阅读(254)  评论(0编辑  收藏  举报