用于编写过滤字符流的抽象类。抽象类FilterWriter本身提供了将所有请求传递给包含流的默认方法。FilterWriter的子类应该覆盖其中一些方法,还可以提供其他方法和字段。 建造师:
null
- 受保护的 FilterWriter(编写器输出): 创建一个新的过滤编写器。
方法:
- void close(): 关闭水流,先冲洗。一旦流被关闭,进一步的write()或flush()调用将导致引发IOException。关闭以前关闭的流没有效果。
Syntax :public void close() throws IOException Throws: IOException
- 无效刷新(): 冲水。
Syntax :public void flush() throws IOException Throws: IOException
- 无效写入(字符[]cbuf,整型关闭,整型长度): 写入字符数组的一部分。
Syntax :public void write(char[] cbuf, int off, int len) throws IOException Parameters: cbuf - Buffer of characters to be written off - Offset from which to start reading characters len - Number of characters to be written Throws: IOException
- 无效写入(int c): 只写一个字符。
Syntax :public void write(int c) throws IOException Parameters: c - int specifying a character to be written Throws: IOException
- 无效写入(字符串str、int off、int len): 写入字符串的一部分。
Syntax :public void write(String str, int off, int len) throws IOException Parameters: str - String to be written off - Offset from which to start reading characters len - Number of characters to be written Throws: IOException
节目:
//Java program demonstrating FilterWriter methods import java.io.FilterWriter; import java.io.StringWriter; import java.io.Writer; class FilterWriterDemo { public static void main(String[] args) throws Exception { FilterWriter fr = null ; Writer wr = null ; wr = new StringWriter(); fr = new FilterWriter(wr) {} ; String str = "Geeksfor" ; char c[] = { 'G' , 'e' , 'e' , 'k' }; //illustrating write(String str,int off,int len) fr.write(str); //illustrating flush() fr.flush(); //illustrating write(char[] cff,int off,int len) fr.write(c); //illustrating write(int c) fr.write( 's' ); System.out.print(wr.toString()); //close the stream fr.close(); } } |
输出:
GeeksforGeeks
本文由 尼森特·夏尔马 .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 贡献极客。组织 或者把你的文章寄到contribute@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。
如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END