[JAVA学习笔记-62]inputstream及几个相关的类

Class InputStream     【字节流的基类】
【This is an abstract class,it is the superclass of all classes representing an input stream of bytes.
所有代表字节流的对象的超类,其子类都需要实现read接口,此接口返回字节流中的下一个字节(可以理解为当前
字节流队列的首字节),无参的read()方法每次仅读取一个字节;read有其它接口,可以将字节流读入到一个buffer中。】
java.lang.Object
java.io.InputStream

All Implemented Interfaces:
Closeable, AutoCloseable


Direct Known Subclasses:
AudioInputStream, ByteArrayInputStream, FileInputStream, FilterInputStream, InputStream, ObjectInputStream, PipedInputStream, SequenceInputStream, StringBufferInputStream


常用的接口:
abstract int read()
【Reads the next byte of data from the input stream.The value of the byte is retured as an int.】
int read(byte[] b)
【Reads some number of bytes from the input stream and stores them into the buffer array b.】
int read(byte[] b, int off, int len)
【Reads up to len bytes of data from the input stream into an array of bytes.】
=====================================================================
Class FileInputStream      【从某个文件读取原始数据的字节流】
【Obtains bytes stream from a file in a file system,it is meant for reading streams of raw bytes 
such as image data.
用于读取文件的原始字节流,文件可以是任何形式,例如文本,图片,音频】
java.lang.Object
java.io.InputStream
java.io.FileInputStream
===============================================================
Class BufferedInputStream  【对原始字节流进行缓存操作】
【A buffer of an inputstream.将inputstream封装在缓存里,从而能像操作一个buffer一样操作inputstream,例如,可以mark,reset。
BufferedInputStream中的字节被读取后,内部的buffer会自动的从inputstream中读入多个字节以补充。
reset操作:从最近一次mark操作的位置开始,重新读取这些字节,然后再从inputstream中补充读取。

java.lang.Object
java.io.InputStream
java.io.FilterInputStream
java.io.BufferedInputStream
All Implemented Interfaces:
Closeable, AutoCloseable


public class BufferedInputStream
extends FilterInputStream


================================================================
Class InputStreamReader   【将字节流转换成字符流】
【A bridge from byte stream to character stream,it reads bytes from byte stream and decodes them
into characters using the specified charset】


java.lang.Object
java.io.Reader
java.io.InputStreamReader
All Implemented Interfaces:
Closeable, AutoCloseable, Readable
================================================================
Class BufferedReader 【将字符流缓存,提高读写效率】
【Reads text from a character-input stream,buffering the characters so as to provide for the efficient
reading of characters,arrays.and lines.
用于读取字符流,并进行缓存,例如读取一个文件,如果使用字符流对象读取(InputstreamReader),每次读取
都需要访问文件,打开并读取字符,然后返回,如果使用BufferedReader,则整个文件被缓存在内存中,每次读取内存即可,
效率大幅提升。】
java.lang.Object
java.io.Reader
java.io.BufferedReader

All Implemented Interfaces:
Closeable, AutoCloseable, Readable
==============================================================
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值