字符串编码转换(java)

字符在java都是以unicode码的方式存在的,因此字符编码方式的转换其实就是一个编码方式先转换成unicode码,再由unicode码转成另一个编码方式。

例如:

String str="";//这个字的编码取决于你的文件保存编码方式
  System.out.println(new String(str.getBytes("GBK"),"GBK"));//转GBK
  System.out.println(new String(str.getBytes("UTF-8"),"UTF-8"));//转utt-8
  System.out.println(new String(str.getBytes("GB18030"),"GB18030"));//转gb18030




猜你喜欢

转载自blog.csdn.net/weixin_38015863/article/details/80729608