編碼:字符串變成字節(jié)數(shù)組嫡锌。
String -->byte[]; str.getBytes(charsetName);
解碼:字節(jié)數(shù)組變成字符串玻侥。
byte[] -->String; new String(byte[],charsetName);
import java.util.*;
class EncodeDemo
{
public static void main(String[] args) throws Exception
{
String s = "小蘿莉漫許可證";
byte[] b1 = s.getBytes("GBK");
System.out.println(Arrays.toString(b1));
String s1 = new String(b1,"iso8859-1");
System.out.println("s1="+s1);
//對s1進(jìn)行iso8859-1編碼
byte[] b2 = s1.getBytes("iso8859-1");
System.out.println(Arrays.toString(b2));
String s2 = new String(b2,"gbk");
System.out.println("s2="+s2);
}
}