java Reader与Weiter.
Java中提供了处理以16位的Unicode码表示的字符流的类,即以Reader和Writer为基类派生处的一系列类
这两个类是抽象类,只是提供了一系列用于字符流处理的接口。不能生成这两个类的实例,只能通过使用由它们派生出来的子类对象来处理字符流
Reader类是处理所有字符流输入类的父类
读取字符
public int read()throws IOException;//读取一个字符,返回值为读取的字符
public int read(char cbuf[])throws IOException;//读取一系列字符到数组cbuf[]中,返回值为实际读取的字符的 数量
public abstract int read(char cbuf[],int off[],int len)throws IOException;
//读取len个字符,从数组cbuf[]的下标off处开始存放,返回值为实际读取的字符数量,该方法必须由子类实现
Reader类
标记类
public boolean markSupported();//判断当前流是否支持做标记
public void mark(int readAheadLimit) throws IOException;//给当前流作标记,最多支持readAheadLimit个字符 的回溯
public void reset() throws IOException;//将当前流重置到做标记处
关闭流
public abstract void close() throws IOException;
Writer类是处理所有字符流输出类的父类
向输出流写入字符
public void write(int c) throws IOException;//将整形值c的低16位写入输出流
public void write(char cbuf[]) throws IOException;//将字符数组cbuf[]写进输出流
public abstract void write(char cbuf[],int off,int len) throws IOException;
//将字符数组cbuf[]中的从索引位off的位置处开始的len个字符写入输出流
public void write(String str) throws IOException;//将字符串str中的字符写入输出流
public void write(String str,int off,int len)throws IOException;
//将字符串str中从索引off开始处的len个字符写入输出流
flush() 刷空输出流,并输出所有被缓存的字节
关闭流
public abstract void close() throws IOException;