08_流

1.在java,对于数据的输入/输出操作以流方式进行。JDK中提供了各种各样的流类,用于获取不同种类的数据,程序中通过标准的方法输入/输出数据

2.从不同角度对流分类:

数据流的方向:输入流和输出流(站在程序的角度看)

处理数据单位:字节流和字符流

功能:节点流和处理流

3.JDK提供的所有流类型位于java.io包内,分别继承自以下四种抽象流类型

4.InputStream的基本方法

int read() throws IOException 读一个字节,如果所有都已读完,返回-1

int read(byte[] buffer) throws IOException 读到buffer字节数组中,返回实际读取的字节数,读完返回-1

int read(byte[] buffer, int offset, int length) throws IOException

void close() throws IOException

5.OutputStream的基本方法

void write(int b) throws IOException 向输入流中写一个字节,该字节数据为参数b的低8位

void write(byte[] buffer) throws IOException 

void write(byte[] buffer, int offset, int length) throws IOException

void close() throws IOException

 void flush() throws IOException 将缓冲的数据全部写到目的地

6.Reader的基本方法

int read() throws IOException 

int read(char[] buffer) throws IOException 

int read(char[] buffer, int offset, int length) throws IOException

void close() throws IOException

7.Writer的基本方法

void write(int b) throws IOException 向输入流中写一个字符,该字符数据为参数b的低16位

void write(char[] buffer) throws IOException 

void write(char[] buffer, int offset, int length) throws IOException

void write(String str) throws IOException 将一个字符串中的字符写入到输出流,这里用的String类的toCharArray()方法

void write(String str, int offset, int length) throws IOException

void close() throws IOException

 void flush() throws IOException 将缓冲的数据全部写到目的地

8.

猜你喜欢

转载自www.cnblogs.com/yxfyg/p/12330338.html