学习Java第八周

1.流的分类

1、字节流:Stream

2、字符流: Writer,Reader

输入流 :InputStream ,Reader

输出流 :OuputStream,Writer

字节流重要还是字符流重要:字节流:字节流类为处理字节式输入/输出提供了丰富的环境。

不仅仅可以读二进制,也可以读文本。 字符流:只能读文本。

流的分类:

字节输入流:InputStream

字节输出流:OuputStream

字符输入流:Reader

字符输出流:Writer

2.InputStream流

1、public abstract class InputStream 见到抽象,不能用它创建对象。

2、方法:

public abstract int read() throws IOException

public int read(byte b[]) throws IOException 

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

public int available() throws IOException //返回有效字节数。

available方法的作用:取得有效字节数。不调用read()方法的时候,文件指针指向第一个字符前,后面有文件大小个字符没有读。

public void close() throws IOException 关闭。

3.OutputStream字节输出流

1、public abstract class OutputStream 

2、方法:

public abstract void write(int b) throws IOException

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

public void flush() throws IOException 清理缓存。

public void close() throws IOException

4.字符输入流Reader

1、public abstract class Reader

2、方法:

 public abstract int read() throws IOException

posted @ 2019-08-25 11:43  祈欢  阅读(148)  评论(0编辑  收藏  举报