【小程序】使用io流实现对字符串的编码和解码

来源:互联网 发布:淘宝售后客服工作总结 编辑:程序博客网 时间:2024/06/09 22:50



import java.io.UnsupportedEncodingException;
import java.util.Arrays;


/*
 * 编码:字符串变成字节数组
 * string-->byte[];str.getBytes();
 * 
 * 解码:字节数组变成字符串
 * byte[]-->string :new string (byte[]);
 * 
 */
public class EncodeDemo {
public static void main(String[] args) throws UnsupportedEncodingException {
String s="你好";
System.out.println("s1="+s);
byte[] b1=s.getBytes("GBK");//输出的为编码
byte[] b2=s.getBytes("UTF-8");//输出的为编码
System.out.println(Arrays.toString(b1));
}
}
0 0
原创粉丝点击