Java FilterOutputStream Class

Last Updated : 23 Jan 2026

The FilterOutputStream class in Java is used to wrap another output stream and add additional functionality while writing data.

In this chapter, we will learn what the FilterOutputStream class is, why it is used, its declaration, constructor, methods, and how to write data using an example.

What is FilterOutputStream in Java?

The FilterOutputStream class is a wrapper output stream that extends the OutputStream class, and it is used to filter or modify the data written to another output stream.

It acts as a base class for other output stream classes such as BufferedOutputStream and DataOutputStream. Because of this, it is rarely used directly in applications.

FilterOutputStream Class Declaration

The following declaration shows how the FilterOutputStream class is defined:

Constructor of FilterOutputStream Class

The FilterOutputStream class provides a constructor to wrap an existing output stream.

FilterOutputStream(OutputStream out)

This constructor creates a new FilterOutputStream that writes data to the specified output stream.

Syntax:

Here is the syntax of the constructor:

Example

The following example demonstrates how to create a FilterOutputStream object.

Methods of FilterOutputStream Class

The FilterOutputStream class provides methods to write and manage output data.

MethodDescription
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

This example demonstrates how to write data to a file using the FilterOutputStream class.

Output:

Success...

testout.txt

Welcome to javaTpoint.