三.字节流与字符流
一.操作主要方法
(1)使用File类打开一个文件
(2)通过字节流或字符流的子类指定输出的位置
(3)进行读/写操作
(4)关闭输入/输出
outputString类常用方法
方法或常量 | 类型 | 描述 |
public void close() throws IOException | 普通 | 关闭输出流 |
public void flush() throws IOException | 普通 | 刷新缓存区 |
public void write(byte[] b)throws IOException | 普通 | 将一个byte数组写入数据流 |
public void write(byte[] b,int off,int len throws) IOException |
普通 | j将一个指定范围的byte数组写入数据流 |
public abstract void write(int b)throws IOException | 普通 | 将一个字节流数据写数据流 |
InputStream类常用方法
方法或常量 | 类型 | 描述 |
public void available() throws IOException | 普通 | 可以取得输入文件的大小 |
public void close() throws IOException | 普通 | 关闭输入流 |
public abstract int read() throws IOException | 普通 | 读取内容,以数字的方式读取 |
public int read(byte[] b)throws IOException | 普通 | 将内容读到byte数组之中,同时返回读入的个数 |
write类的操作方法
方法或常量 | 类型 | 描述 |
public abstract void close() throws IOException | 普通 | 关闭输出流 |
public void write (String str)throws IOException | 普通 | 将字符串输出 |
public void write (char[] cbuf)throws IOException | 普通 | 将字符数组输出 |
public abstract void flush() throws IOException | 普通 | 强制性清空缓存 |
Reader类的常用方法
方法或常量 | 类型 | 描述 |
public abstract void close() throws IOException | 普通 | 关闭输出流 |
public int read() throws IOException | 普通 | 读取单个字符 |
public int read(char[] cbuf)throws IOException | 普通 | 将内容读到字符数组之中,返回读入的长度 |