Read
抽象类,proteated修饰
int read() //读取单个字符,返回char
int read(Char[])
FileReader
继承AutoCloseable,可能会抛出FileNotFound异常
构造5种:
FileReader(File file)
FileReader(File file, Charset charset)
FileReader(String fileName)
FileReader(String fileName, Charset charset)
markSupport():false,不支持
getEncoding()返回当前字符集
FileWriter
继承AutoCloseable接口
构造:
FileWriter(File file)
FileWriter(File file, boolean append)
FileWriter(File file, Charset charset)
FileWriter(File file, Charset charset, boolean append)
FileWriter(String fileName)
FileWriter(String fileName, boolean append)
FileWriter(String fileName, Charset charset)
FileWriter(String fileName, Charset charset, boolean append)
方法:
append与write一样,将字符序列拼接返回输出流
字符输出流写完必须刷新关闭
缓存流:
使用内部缓存区暂时存储数据,若数据写入前发生程序崩溃和异常,会数据丢失损坏
字节缓存流
BufferedInputStream
支持markSupported,为FileOutputStream子类
s.mark() //当前流的位置标记,与底层缓存数据比较,取最大值
s.set() //返回标记处
构造:
BufferedInputStream(InputStream in)
BufferedInputStream(InputStream in, int size)
方法:
BufferedOutputStream
构造:
BufferedOutputStream(OutputStream out)
BufferedOutputStream(OutputStream out, int size)
方法:
字符缓存流
BufferReader:
字符缓存输入流,实现AutoCloneable接口,Read的子类
构造:
BufferedReader(Reader in)
BufferedReader(Reader in, int sz)
BufferWriter:字符缓存输出流,实现AutoCloseable接口
构造:
BufferedWriter(Writer out)
BufferedWriter(Writer out, int sz)
方法: