logo

Clase Java.io.FilterWriter en Java

Clase abstracta para escribir secuencias de caracteres filtrados. La propia clase abstracta FilterWriter proporciona métodos predeterminados que pasan todas las solicitudes a la secuencia contenida. Las subclases de FilterWriter deberían anular algunos de estos métodos y también pueden proporcionar métodos y campos adicionales. Constructor:
    protegido FilterWriter (escritor): Crea un nuevo escritor filtrado.
Métodos:
    cierre vacío() : 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 
    descarga vacía() : Flushes the stream.
      Syntax :  public void flush() throws IOException   Throws:   IOException
    escritura vacía (char[] cbuf int off 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
    escritura nula (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
    escritura nula (String str int off 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 
Programa : Java
//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 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 stream  fr.close();  } } 
Producción :
GeeksforGeeks
Crear cuestionario