OutputStreamWriter与InputStreamReader(转换流)

 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();
    }
}

 

 

转载于:https://www.cnblogs.com/LO-ME/p/3593977.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值