标签:
import java.io.*; class TransStreamDemo { public static void main(String[] args)throws IOException { /* //从键盘录入数据 InputStream in = System.in; //将字节流对象转换为字符流对象,使用转换流,InputStreanReader InputStreamReader isr = new InputStreamReader(in); //为了提高效率,将字符串进行高效技术操作,即创建字符流缓冲区流对象 BufferedReader bufr = new BufferedReader(isr); */ //上面三个句子简写成:键盘录入最常见写法 BufferedReader bufr = new BufferedReader(new InputStreamReader(System.in)); // OutputStream out = System.out; // OutputStreamWriter osr = new OutputStreamWriter(out); // BufferedWriter bufw = new BufferedWriter(osr); //上面三个句子简写成: BufferedWriter bufw = new BufferedWriter(new OutputStreamWriter(System.out)); String line = null; while((line = bufr.readLine())!=null) { if("over".equals(line)) break; bufw.write(line.toUpperCase()); bufw.newLine(); bufw.flush(); } bufr.close(); /* String line = null; while((line = bufr.readLine())!=null) { if("over".equals(line)) break; System.out.println(line.toString()); } buf.close(); */ } }
import java.io.*; class TransStreamDemo2 { public static void main(String[] args)throws IOException { //System.setIn(new FileInputStream("ReadInDemo.java"));//修改读取源 //System.setOut(new PrintStream("f:\\myfile\\trans.txt"));//修改打印目的地 BufferedReader bufr = new BufferedReader(new InputStreamReader(System.in));//从键盘读入 BufferedWriter bufw = new BufferedWriter(new OutputStreamWriter(System.out));//打印在控制台上 String line = null; while((line = bufr.readLine())!=null) { if("over".equals(line)) break; bufw.write(line.toUpperCase()); bufw.newLine(); bufw.flush(); } bufr.close(); } }
标签:
原文地址:http://www.cnblogs.com/XYQ-208910/p/4918556.html