黑马程序员:字符编码

来源:互联网 发布:mtkoala男友知乎 编辑:程序博客网 时间:2024/05/21 18:23

---------------------- ASP.Net+Unity开发、.Net培训、期待与您交流! ---------------------- 

1、字符流的出现为了方便操作字符

2、更重要的是加入了编码转换

3、通过子类转换流来完成

     InputStreamReader

     OutputStreamWriter

4、在两个对象进行构造的时候可以加入字符集

 

常见的编码表

ASCII,ISO8859-1,GB2312,GBK,Unicode,UTF-8

class  EncodeStream{public static void writeText()throws IOException{  OutputStreamWriter sow=new OutputStreamWriter(new FileOutputStream("gbk.txt","GBK"));  osw.write("你好");  osw.close();}public static void readText()throws IOException{   InputStreamReader isr=new InputStreamReader(new FileOutputStream("gbk.txt"),"GBK");   char[] buf=new char[10];   in len=isr.read(buf);   String str=new String(buf,0,len);   sop(str);   isr.close();}public static void sop(Object obj){  System.out.println(obj);}public static void main(String[] args) {System.out.println("Hello World!");}}


编码:字符串编程字节数组

解码:字节数组编程字符串

String——>byte[];    str.getBytes(charsetName)

byte[]——>String;    new String(byte[],charsetName)

---------------------- ASP.Net+Unity开发、.Net培训、期待与您交流! ----------------------
0 0
原创粉丝点击