标签:
/**/
package io.编码解码; import java.io.UnsupportedEncodingException; import java.util.Arrays; public class StringDemo { public static void main(String[] args) throws UnsupportedEncodingException { String s = "你好"; //String --byte[] // byte[] bys = s.getBytes();//[-28, -67, -96, -27, -91, -67] // byte[] bys = s.getBytes("GBK");//[-60, -29, -70, -61] byte[] bys = s.getBytes("UTF-8");//[-28, -67, -96, -27, -91, -67] //所以默认的编码是UTF-8 System.out.println("字符串到字节数组:"+Arrays.toString(bys)); //解码 //byte[] ---String // String ss = new String(bys);//你好 // String ss = new String(bys,"GBK");//浣犲ソ String ss = new String(bys,"UTF-8");//你好 //所以m默认的解码是UTF-8 System.out.println("字节数组到字符串:"+ss); } }
标签:
原文地址:http://blog.csdn.net/u012110719/article/details/46287635