Java Filterinputstream Class - Java Tutorial

Java Filterinputstream Class

BLUF: Mastering Java Filterinputstream Class is a key requirement for any Java developer. This lesson breaks down the object-oriented principles and syntax required to use this concept in real-world applications.
Write Once, Run Anywhere Tip: Java Filterinputstream Class

Java's versatility is unmatched. Learn how Java Filterinputstream Class fits into the Java ecosystem and improves your code structure in the tutorial below.

The FilterInputStream class in Java serves as an implementation of the InputStream interface. It includes various subclasses like BufferedInputStream and DataInputStream, which offer extra features. Consequently, it is not commonly utilized on its own.

Java FilterInputStream class declaration

Let's examine the declaration of the java.io.FilterInputStream class.

Example

public class FilterInputStream extends InputStream

Java FilterInputStream class Methods

Method Description
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

Example

import java.io.*;

public class FilterExample {

	public static void main(String[] args) throws IOException {

		File data = new File("D:\\testout.txt");

		FileInputStream  file = new FileInputStream(data);

		FilterInputStream filter = new BufferedInputStream(file);

		int k =0;

		while((k=filter.read())!=-1){

			System.out.print((char)k);

		}

		file.close();

		filter.close();

	}

}

It is assumed that the data in question is stored in a file named "testout.txt".

Example

Welcome to hello world

Output:

Output

Welcome to hello world

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience