1 import java.io.BufferedReader; 2 import java.io.BufferedWriter; 3 import java.io.IOException; 4 import java.io.InputStream; 5 import java.io.InputStreamReader; 6 import java.io.OutputStream; 7 import java.io.OutputStreamWriter; 8 9 public class TransStreamDemo { 10 public static void main(String[] args) throws IOException { 11 //获取键盘录入对象 12 //InputStream in = System.in; 13 14 //将字节流对象转换成字符流对象,使用转换流,InputStreamReader 15 //InputStreamReader isr = new InputStreamReader(in); 16 17 //为了提高效率,将字符串进行缓冲区技术高效操作,使用BufferReader 18 //BufferedReader buf = new BufferedReader(isr); 19 20 //把上面三句话变成一句话 21 BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); 22 23 //OutputStream out = System.out; 24 25 //OutputStreamWriter osw = new OutputStreamWriter(out); 26 27 //BufferedWriter buw = new BufferedWriter(osw); 28 BufferedWriter buw = new BufferedWriter(new OutputStreamWriter(System.out)); 29 30 String line = null; 31 while((line = buf.readLine())!=null){ 32 if ("over".equals(line)) 33 break; 34 //System.out.println(line.toUpperCase()); 35 36 buw.write(line.toUpperCase()); 37 buw.newLine(); 38 buw.flush(); 39 } 40 buw.close(); 41 buf.close(); 42 } 43 }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; public class TransStreamTest { public static void main(String[] args) throws IOException { BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter buw = new BufferedWriter(new OutputStreamWriter(System.out)); /* 将键盘录入写到一个文件 中 BufferedWriter buw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("F:\\a.txt"))); 将文件中的内容 打印到控制台上 BufferedReader buf = new BufferedReader(new InputStreamReader(new FileInputStream("F:\\a.txt"))); 将一个文件中的内容复制到另一个文件中 BufferedWriter buw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("F:\\a.txt"))); BufferedReader buf = new BufferedReader(new InputStreamReader(new FileInputStream("F:\\b.txt"))); */ String line = null; while((line = buf.readLine())!=null){ if ("over".equals(line)) break; //System.out.println(line.toUpperCase()); buw.write(line.toUpperCase()); buw.newLine(); buw.flush(); } buw.close(); buf.close(); } }