IO Stream - 字符流

2021-09-02  本文已影响0人  七喜丶

字符流

代码演示

public class StringDemo { public static void main(String[] args) throws UnsupportedEncodingException { 
//定义一个字符串 
String s = "中国"; 
//byte[] bys = s.getBytes(); //[‐28, ‐72, ‐83, ‐27, ‐101, ‐67]
 //byte[] bys = s.getBytes("UTF‐8"); //[‐28, ‐72, ‐83, ‐27, ‐101, ‐67] 
byte[] bys = s.getBytes("GBK"); //[‐42, ‐48, ‐71, ‐6]
System.out.println(Arrays.toString(bys)); 
//String ss = new String(bys); 
//String ss = new String(bys,"UTF‐8"); 
String ss = new String(bys,"GBK"); 
System.out.println(ss); } }

IO流小结

上一篇下一篇

猜你喜欢

热点阅读