The Closeable, Flushable, Readable, and Appendable interfaces

 


The Closeable, Flushable, Readable, and Appendable interfaces

 

Java SE 5.0引入了4个附加的接口:Closeable、Flushable、Readable和Appendable。
Closeable拥有方法 void close() throws IOException;
Flushable拥有方法 void flush() throws IOException;
Readable拥有方法 public int read(java.nio.CharBuffer cb) throws IOException;
    CharBuffer类拥有按顺序和随机的进行读写访问的方法,它表示一个内存中的缓冲区或者一个内存映像的文件。
Appendable拥有方法
Appendable append(CharSequence csq) throws IOException; //向此 Appendable 添加指定的字符序列。
Appendable append(CharSequence csq, int start, int end) throws IOException; //向此 Appendable 添加指定字符序列的子序列。
Appendable append(char c) throws IOException;   //向此 Appendable 添加指定字符。
    CharSequence接口描述了一个char值序列的基本属性,它是用String、CharBuffer、StringBuilder和StringBuffer来实现的。
InputStream、OutputStream、Reader和Writer都实行了Closeable接口,而OutputStream和Writer还实现了Flushable接口。只有Writer实现了Appendable接口