InputStreamReader、BufferedReader输出内容的区别

很早之前写过一个小项目,是关于某个音游自制谱面文件内语法内容错误检查的。昨天回看项目时,发现自己在读取文件时使用了 BufferedReader 而注释掉了 InputStreamReader 所以想试试这二者输出的不同。


1.InputStreamReader

处理字符流的抽象类,是字节流通向字符流的桥梁,它将字节流转换为字符流.

2.BufferedReader

由Reader类扩展而来,提供通用的缓冲方式文本读取,readLine读取一个文本行,从字符输入流中读取文本,缓冲各个字符,从而提供字符、数组和行的高效读取。


目标文件:

BufferedReader

 public void input() throws IOException {
//        maidataContent = "";
        File txtfile = new File("D:\\Maidata.txt");
//        InputStreamReader read = new InputStreamReader(new FileInputStream(txtfile), "UTF-8");
        BufferedReader br = new BufferedReader(new FileReader(txtfile));
        String txtLine = null;
        while((txtLine = br.readLine())!=null){//使用readLine方法,一次读一行
//            TXTString.add(txtLine);
            System.out.println(txtLine);
        break:
}
}

输出:&title=Caterpillar Song

 

InputStreamReader

 public void input() throws IOException {
//        maidataContent = "";
        File txtfile = new File("D:\\Maidata.txt");
        InputStreamReader read = new InputStreamReader(new FileInputStream(txtfile), "UTF-8");
//        BufferedReader br = new BufferedReader(new FileReader(txtfile));
        String txtLine = null;
        int i;
        while((i = read.read() )!=-1){//使用readLine方法,一次读一行
//            TXTString.add(txtLine);
            System.out.println(i);
        break;
}
}

输出:&

 


由此可见, 

InputStreamReader输出单个字符

BufferedReader输出一行字符串

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值