Introduction
In this article, we will be covering the FilterInput/OutputStream. However, before moving to the actual topic, we need to revise some previous concepts, which might help. Java Input/Output is a robust operation that provides all the input and output operations. A stream is a logical connection between a Java program and a file. The byte stream is usually used to perform an output and input function on 8-bits bytes.
Must Read, Multithreading in java and Hashcode Method in Java
Java FilterInputStream Class
Java FilterInputStream class contains different subclasses such as BufferedInputStream, DataInputStream to provide additional functionality. This class implements the InputStream. This is used occasionally.
Declaration
public class FilterInputStream extends InputStream
Content of input.txt
Hello This is File Input/Output Filter
Code 1
import java.io.*;
public class InputFilter1 {
public static void main(String[] args) throws IOException {
File data = new File("input.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();
}
}
Output
Hello This is File Input/Output Filter
In this example, we have taken the use of Filter Input Stream. We have taken a file as an input, and we have printed the file's content.
Practice by yourself on java online compiler.