字符在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