Java FilterInputStream Class

Last Updated : 23 Jan 2026

The FilterInputStream class in Java is used to wrap another input stream and provide additional functionality while reading data.

In this chapter, we will learn what the FilterInputStream class is, why it is used, its declaration, constructor, methods, and how it works with an example.

What is FilterInputStream in Java?

The FilterInputStream class is an input stream that wraps another InputStream, and it is used to filter or modify the data while reading from the stream.

It acts as a base class for other input stream classes such as BufferedInputStream, DataInputStream. Due to this reason, it is rarely used directly in applications and is mainly used as a superclass.

FilterInputStream Class Declaration

The following declaration shows how the FilterInputStream class is defined in Java.

Constructor of FilterInputStream Class

The FilterInputStream class provides a constructor to wrap an existing input stream.

FilterInputStream(InputStream in)

This constructor creates a new FilterInputStream that reads data from the specified input stream.

Syntax:

Here is the syntax of the constructor:

Example

The following example demonstrates how to create a FilterInputStream object.

Methods of FilterInputStream Class

The FilterInputStream class provides methods to read and manage input data.

MethodDescription
int available()It is used to return an estimate number of bytes that can be read from the input stream.
int read()It is used to read the next byte of data from the input stream.
int read(byte[] b)It is used to read up to byte.length bytes of data from the input stream.
long skip(long n)It is used to skip over and discards n bytes of data from the input stream.
boolean markSupported()It is used to test if the input stream support mark and reset method.
void mark(int readlimit)It is used to mark the current position in the input stream.
void reset()It is used to reset the input stream.
void close()It is used to close the input stream.

Example of FilterInputStream Class

This example demonstrates how to read data from a file using the FilterInputStream class.

Here, we are assuming that you have following data in "testout.txt" file:

Welcome to javatpoint

Output:

Welcome to javatpoint