Java IO系列0 InputStream与OutputStream(字节流)
2015-12-22 16:55
676 查看
该系列的分析源码基于Java 1.8.0_45
Since:JDK1.0
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
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
一、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
相关文章推荐
- java性能优化读书笔记之三《程序优化===集合优化(Map)》
- Java中 键盘录入Scanner,String与 Integer数据类型转换
- Java — 面向对象
- Spirng+SpringMVC+Maven+Mybatis+MySQL项目搭建
- Spirng+SpringMVC+Maven+Mybatis+MySQL项目搭建
- (Singleton)单例模式的Java实现
- Spring MVC 解读
- 【java学习笔记s】多态
- Eclipse下Properties解析(重要的可修改的会用红笔标注)
- 关于java.lang.UnsatisfiedLinkError的处理
- Spring4.2.0 MVC json问题(406 Not Acceptable) 真的很蛋疼,耗时半天
- Setting property 'source' to 'org.eclipse.jst.jee.server:web' did not find a matching property原因?
- Spring单实例、多线程安全、事务解析
- Java线程池的工作原理与实现
- 利用FreeMarker生成java源代码
- think in java (com.bruceeckel.simpletest)配置
- 自己用java写了一款日志查找分析工具
- ubuntu 一键安装jdk 1.79
- Eclipse中快捷键的使用
- Spring 学习笔记 (I) 之 Spring IoC