The Java FilterOutputStream class is an implementation of the OutputStream class. It offers various subclasses like BufferedOutputStream and DataOutputStream to extend its capabilities, making it more commonly utilized as part of a larger functionality rather than on its own.
Java FilterOutputStream class declaration
Now we will examine the declaration of the java.io.FilterOutputStream class:
Example
public class FilterOutputStream extends OutputStream
Java FilterOutputStream class Methods
Below are various techniques of the Java FilterOutputStream class:
| Method | Description |
|---|---|
| void write(int b) | It is used to write the specified byte to the output stream. |
| void write(byte[] ary) | It is used to write ary.length byte to the output stream. |
| void write(byte[] b, int off, int len) | It is used to write len bytes from the offset off to the output stream. |
| void flush() | It is used to flushes the output stream. |
| void close() | It is used to close the output stream. |
Example of FilterOutputStream class
Consider an example to demonstrate the application of the FilterOutputStream class in Java.
Example
import java.io.*;
public class FilterExample {
public static void main(String[] args) throws IOException {
File data = new File("D:\\testout.txt");
FileOutputStream file = new FileOutputStream(data);
FilterOutputStream filter = new FilterOutputStream(file);
String s="Welcome to Java.";
byte b[]=s.getBytes();
filter.write(b);
filter.flush();
filter.close();
file.close();
System.out.println("Success...");
}
}
Output:
Output
Success...
testout.txt
Example
Welcome to Java.