- Java中接收输入的流表示
-
- 类示意图:
- 针对缓存的:
- ByteArrayInputStream
- StringBufferInputStream
- 针对文件的:FileInputStream
- 针对对象:ObjectInputStream
- 针对线程的:PipedInputStream
- 针对过滤器:FilterInputStream
- DataInputStream
- BufferedInputStream
- 针对缓存的:
- 超级基类:InputStream
- 读取一定字节到字节数组中:
- public int read(byte b[]) throws IOException
- public int read(byte b[], int off, int len) throws IOException
- 跳过n个字符:public long skip(long n) throws IOException
- 可读取的字节数:public int available() throws IOException
- 关闭流:public void close() throws IOException
- 是否支持标记:public boolean markSupported()
- 标志:public synchronized void mark(int readlimit){}
- 读取一定字节到字节数组中:
- 字节数组输入流:ByteArrayInputStream
- 数据元素
- 字节数组:protected byte buf[];
- 当前位置:protected int pos;
- 当前标记,很多时候就是当前位置:protected int mark = 0;
- 字节数组元素数量:protected int count;
- 方法:
-
- 读取一定字节到字节数组中: public int read(byte b[]) throws IOException
- 读取一定字节到字节数组中: public int read(byte b[], int off, int len) throws IOException
- 跳过n个字符:public long skip(long n) throws IOException
- 可读取的字节数:public int available() throws IOException
- 关闭流:public void close() throws IOException
- 是否支持标记:public boolean markSupported()
- 标志:public synchronized void mark(int readlimit){}
-
- 数据元素
- 文件输入流:FileInputStream
- 读取一定字节到字节数组中: public int read(byte b[]) throws IOException
- private native int readBytes(byte b[], int off, int len) throws IOException;
- public native long skip(long n) throws IOException;
- public native int available() throws IOException;
- 关闭流:public void close() throws IOException
- private native void close0() throws IOException;
- 读取一定字节到字节数组中: public int read(byte b[]) throws IOException
- 管道输入流:PipedInputStream
- 合并具体的输入流:SequenceInputStream
- 数据元素
- Enumeration e;
- InputStream in;
- public SequenceInputStream(Enumeration<? extends InputStream> e)
- 数据元素
- 过滤输入流:FilterInputStream
- 数据成员
- protected volatile InputStream in;
- 方法:通过通过in调用相关的方法,构造方法就是接受外面的输入对象,比如:ByteArrayInputStream、FileInputStream、PipedInputStream等,实际上调用的就是传进来的对象
- 数据成员
- BufferedInputStream:缓冲区操作
- DataInputStream:适应各种数据类型的输入
- 超级基类:DataInput:接口用于从二进制流中读取字节,并根据所有 Java 基本类型数据进行重构
- 读取字节:void readFully(byte b[]) throws IOException;
- 读取字节:void readFully(byte b[], int off, int len) throws IOException;
- 跳过字节:int skipBytes(int n) throws IOException;
- 读取布尔类型:boolean readBoolean() throws IOException;
- 读取字节:byte readByte() throws IOException;
- 读取无符号字节:int readUnsignedByte() throws IOException;
- 读取短整型:short readShort() throws IOException;
- 读取整型:int readUnsignedShort() throws IOException;
- 读取字符:char readChar() throws IOException;
- 读取整型:int readInt() throws IOException;
- 读取长整型:long readLong() throws IOException;
- 读取浮点:float readFloat() throws IOException;
- 读取double:double readDouble() throws IOException;
- 读取一行:String readLine() throws IOException;
- DataInputStream:实现 DataInput 各个方法
- 超级基类:DataInput:接口用于从二进制流中读取字节,并根据所有 Java 基本类型数据进行重构
- 类示意图: