UTF-8,GBK,ISO8859-1
package com.page2;
public class demobytes {
public static void main(String[] args) {
String str="陈";
try {
byte[] byte1 = str.getBytes("GBK");
byte[] byte2 = str.getBytes("UTF-8");
byte[] byte3 = str.getBytes("ISO8859-1");
System.out.println("GBK");
for (byte i : byte1)
System.out.println(i);
System.out.println("UTF-8");
for (byte i : byte2)
System.out.println(i);
System.out.println("ISO8859-1");
for (byte i : byte3)
System.out.println(i);
String str1 = new String(byte1, "GBK");
System.out.println("GBK还原"+str1);
String str2= new String(byte2, "UTF-8");
System.out.println("utf8还原"+str2);
String str3 = new String(byte3, "ISO8859-1");
System.out.println("iso8859-1还原"+str3);
byte[] utf8=str.getBytes("UTF-8");
String iso8859_1=new String(utf8,"ISO8859-1");
System.out.println("打印iso");
byte[] iso=iso8859_1.getBytes("ISO8859-1");
for(byte i:iso)
{
System.out.println(i);
}
System.out.println("转化为了Iso"+iso8859_1);
String str_han=new String(iso8859_1.getBytes("ISO8859-1"),"UTF-8");
System.out.println("转化为汉字"+str_han);
}
catch (Exception e){
System.err.println(e.getMessage());
}
}
}