标签:iter stream 处理 字节数组 opened cas byte 字符流 java
1 package 内存流; 2 3 import java.io.ByteArrayInputStream; 4 import java.io.ByteArrayOutputStream; 5 import java.io.IOException; 6 import java.io.InputStream; 7 import java.io.OutputStream; 8 9 public class Test { 10 public static void main(String[] args) throws IOException { 11 String str="Hello World!中国好国国国。"; 12 InputStream in=new ByteArrayInputStream(str.getBytes()); 13 OutputStream out=new ByteArrayOutputStream(); 14 int tmp=0; 15 while((tmp=in.read())!=-1) 16 out.write(Character.toUpperCase(tmp)); 17 System.out.println(out);//HELLO WORLD!中冠好冠冠冠。 18 //中文有乱码!!! 19 in.close(); 20 out.close(); 21 } 22 }
1 package 内存流; 2 3 import java.io.CharArrayReader; 4 import java.io.CharArrayWriter; 5 import java.io.IOException; 6 import java.io.Reader; 7 import java.io.Writer; 8 9 public class Test { 10 public static void main(String[] args) throws IOException { 11 String str="Hello World!中国好国国国。"; 12 Reader in=new CharArrayReader(str.toCharArray()); 13 Writer out=new CharArrayWriter(); 14 int tmp=0; 15 while((tmp=in.read())!=-1) 16 out.write(Character.toUpperCase(tmp)); 17 System.out.println(out);//HELLO WORLD!中国好国国国。 18 //字符流处理中文无乱码!!! 19 in.close(); 20 out.close(); 21 } 22 }
标签:iter stream 处理 字节数组 opened cas byte 字符流 java
原文地址:http://www.cnblogs.com/xiongjiawei/p/6684634.html