Abstracte klasse voor het schrijven van gefilterde karakterstromen. De abstracte klasse FilterWriter zelf biedt standaardmethoden die alle verzoeken doorgeven aan de ingesloten stroom. Subklassen van FilterWriter moeten sommige van deze methoden overschrijven en kunnen ook aanvullende methoden en velden bieden. Constructeur:
beschermd FilterWriter(schrijver uit):
Maak een nieuwe gefilterde schrijver. Methoden:
leegte close() :
Closes the stream flushing it first.Once the stream has been closed further write() or flush() invocations will cause an IOException to be thrown. Closing a previously closed stream has no effect.
Syntax : public void close() throws IOException Throws: IOException
leegte flush() :
Flushes the stream.
Syntax : public void flush() throws IOException Throws: IOException
void write(char[] cbuf int uit int len) :
Writes a portion of an array of characters.
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
ongeldig schrijven(int c):
Writes a single character.
Syntax : public void write(int c) throws IOException Parameters: c - int specifying a character to be written Throws: IOException
void write(String str int uit int len) :
Writes a portion of a string.
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
Programma: Java
//Java program demonstrating FilterWriter methodsimportjava.io.FilterWriter;importjava.io.StringWriter;importjava.io.Writer;classFilterWriterDemo{publicstaticvoidmain(String[]args)throwsException{FilterWriterfr=null;Writerwr=null;wr=newStringWriter();fr=newFilterWriter(wr){};Stringstr='Geeksfor';charc[]={'G''e''e''k'};//illustrating write(String strint offint len)fr.write(str);//illustrating flush()fr.flush();//illustrating write(char[] cffint offint len)fr.write(c);//illustrating write(int c)fr.write('s');System.out.print(wr.toString());//close the streamfr.close();}}