Java IO——InputStream,InputStreamReader

    今天在做项目时,最终接触到了我不怎么熟悉的IO方面的知识——IO流。

    这次就在InputStream这个类上出了问题,首先看看官方对InputStream的一些介绍:

    This abstract class is the superclass of all classes representing an input stream of bytes.

Applications that need to define a subclass of InputStream must always provide a method that returns the next byte of input.

    意思是说,这个类是一切表示字节输入流的父类,需要定义一个inputStream的子类一定要提供一个返回输入的下一个字节,也就是说,InputStream是字节输入流的根本。它是一次读出一个字节,但是读出的字节是一种int,需要通过转换手段转换成char字符

    再来看InputStreamReader:

    An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specified charset. The charset that it uses may be specified by name or may be given explicitly, or the platform's default charset may be accepted.

Each invocation of one of an InputStreamReader's read() methods may cause one or more bytes to be read from the underlying byte-input stream. To enable the efficient conversion of bytes to characters, more bytes may be read ahead from the underlying stream than are necessary to satisfy the current read operation.

For top efficiency, consider wrapping an InputStreamReader within a BufferedReader. For example:

 BufferedReader in
   = new BufferedReader(new InputStreamReader(System.in));

    意思是说,inputStreamReader是一个针对字节流的到字符流的桥梁类,用这个类就能将字节流中转化成我们想要看到的字符了。

    所以,在Java中字节流与字符流需要理清楚,不能误认为字节流就是能够看到的字符。


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值