您的位置:首页 > 编程语言 > Java开发

Java IO系列0 InputStream与OutputStream(字节流)

2015-12-22 16:55 676 查看
该系列的分析源码基于Java 1.8.0_45

一、InputStream

public abstract class InputStream extends Object implements Closeable


Since:JDK1.0

private static final int MAX_SKIP_BUFFER_SIZE = 2048;
输入流是可以跳过指定字节,但是我们不可能跳过很长的字节,2048就是最大的值

public abstract int read() throws IOException;

读取下一个位置的字节,返回读取的字节,如果返回-1,说明已经到达流的结尾

public int read(byte b[]) throws IOException {

return read(b, 0, b.length);

}

循环把数据读取到b[]字节数组里,位置从1开始,最多读取b.length个字节

该方法返回读入缓冲区的总字节数

public int read(byte b[], int off, int len) throws IOException

循环把数据读取到b[]字节数组里,位置从off开始,最多读取b.length个字节

该方法返回读入缓冲区的总字节数

public long skip(long n) throws IOException

跳过指定最大字节

返回真实跳过字节数

public int available() throws IOException

public synchronized void mark(int readlimit)

public boolean markSupported()

public synchronized void reset() throws IOException

public void close() throws IOException

二、OutputStream

public abstract class OutputStream extends Object implements Closeable, Flushable

Since:
JDK1.0

public abstract void write(int b) throws IOException;

写入一个字节 public void write(byte b[]) throws IOException

把b[ ]数组里的字节写到输出流中public void write(byte b[], int off, int len) throws IOException

把b[ ]数组里的字节从off位置循环输入len个字节到输入流中 public void flush() throws IOExceptionpublic void close() throws IOException
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: