public static void main(String[] args) throws IOException {
//System.out.println(MD5("2221083" + "20111101" + "pagehis"));
String txt = "我是中国人";
String res = changeCharset(txt, "utf-8");
String result = changeCharset(res, "gbk");
}
private static String changeCharset(String txt, String charsetName) throws IOException {
byte[] buff = new byte[1024];
InputStream is = new ByteArrayInputStream(txt.getBytes(charsetName));
int len = -1;
String res = "";
while(-1 != (len= is.read(buff))){
res = new String(buff, 0, len, charsetName);
}
System.out.println(res);
return res;
}
java字符串根据编码格式互相转换
最新推荐文章于 2024-05-29 21:28:09 发布