IO编程¶
Java中,按照流的数据流向,可以氛围输入流和输出流。按照流处理数据的单位,可以将其区分为字节流和字符流。
1.字节输入流 ¶
字节输入流框架图
1.1InputStream ¶
InputStream是字节输入流的基类。
1.2ByteArrayInputStream ¶
构造函数
- ByteArrayInputStream\(byte\[\] buf\)
- ByteArrayInputStream\(byte\[\] buf, int offset, int length\)
方法
- int read()
- int read\(byte\[\] b, int off, int len\)
- long skip\(long n\)跳过n个字节
1.3FileInputStream ¶
构造函数
- FileInputStream\(File file\)
- FileInputStream\(String name\)
- FileInputStream\(FileDescriptor fdObj\)
方法
- int read()
- int read\(byte\[\] b\):从输入流中读取最多b.length个字节的数据,并将其存储在字节数组中,返回实际读取的字节数。
- int read\(byte\[\] b,int off,int len\):从输入刘中读取最多len个字节数据,存入数组中。并不是从数组起点开始,而是从offset位置开始,返回实际读取的字节数。
1.4BufferedInputStream ¶
BufferedInputStream 的作用是为另一个输入流添加一些功能,例如,提供“缓冲功能”以及支持“mark()标记”和“reset()重置方法”。
2.字节输出流 ¶
字节输出流框架图
2.1OutputStream ¶
OutputStream是字节输出流的基类。
2.2ByteArrayOutputStream ¶
构造函数
- ByteArrayOutputStream()
- ByteArrayOutputStream\(int size\)

