VOOZH about

URL: https://www.geeksforgeeks.org/java/java-io-filteroutputstream-class-java/

⇱ Java.io.FilterOutputStream Class in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java.io.FilterOutputStream Class in Java

Last Updated : 29 Oct, 2022

java.io.FilterInputStream Class in Java

👁 FilterInputStream and FilterOutputStream Class

Java.io.FilterOutputStream class is the superclass of all those classes which filters output streams. The write() method of FilterOutputStream Class filters the data and write it to the underlying stream, filtering which is done depending on the Streams.

Declaration : 

public class FilterOutputStream
 extends OutputStream

Constructors :  

  • FilterOutputStream(OutputStream geekout) : Creates an output stream filter.

Methods: 

  • write(int arg) : java.io.FilterOutputStream.write(int arg) writes specified byte to the Output stream. 
    Syntax : 
public void write(int arg)
Parameters : 
arg : Source Bytes
Return :
void
Exception : 
In case any I/O error occurs.
  • Implementation :
  • Note : 
    In the program I have used GEEKS.txt file, the program will create a new file of the name given in the code and write in it. 
    Output : 
Character written by FilterOutputStream : M
  • write(byte[] buffer) : java.io.FilterOutputStream.write(byte[] buffer) writes 'arg.length' byte to the Output stream. 
    Syntax : 
public void write(byte[] arg)
Parameters : 
buffer : Source Buffer to be written to the Output Stream
Return :
void
Exception : 
In case any I/O error occurs.
  • Implementation :
  • Note : 
    In the program I have use GEEKS.txt file, the program will create a new file of the name given in the code and write in it.

Output :

MOHIT
  • write(byte[] buffer, int offset, int maxlen) : java.io.FilterOutputStream.write(byte[] buffer, int offset, int maxlen) writes maxlen bytes from the specified Buffer starting at offset position to the Output stream.

Syntax : 

public void write(write(byte[] buffer, int offset, int maxlen)
Parameters : 
buffer : Source Buffer to be written to the Output Stream
Return :
buffer : Source Buffer to be written
offset : Starting offset 
maxlen : max no. of bytes to be written to the Output Stream
Exception : 
In case any I/O error occurs.
  • flush() : java.io.FilterOutputStream.flush() flushes the Output Stream and no data is allowed to be written to the Stream. 
    Syntax : 
public void flush()
Parameters : 
------
Return :
void
Exception : 
In case any I/O error occurs.
  • close() : java.io.FilterOutputStream.close() closes the stream and releases all allocated resources to the Stream. 
    Syntax : 
public void close()
Parameters : 
------
Return :
void
Exception : 
In case any I/O error occurs.


Java program illustrating : write(byte[] buffer, int offset, int maxlen), flush(), close() methods

Note : 
In the program I have use GEEKS.txt file, the program will create a new file of the name given in the code and write in it.

Output : 

MOHIT


 

Comment
Article Tags: