The given example uses the BufferedInputstream class that reads the bytes from the input stream. The input stream is a file "Filterfile.txt" from which the data is read in form of a byte through the read( ) method. The read( ) method reads the byte from the file that is converted into the character-form.
import java.io.*; class ReadFilter { public static void main(String args[]) { try { FileInputStream fin = new FileInputStream("Filterfile.txt"); BufferedInputStream bis = new BufferedInputStream(fin); // Now read the buffered stream. while (bis.available() > 0) { System.out.print((char)bis.read()); } } catch (Exception e) { System.err.println("Error reading file: " + e); } } }
Output of the Program:
C:\nisha>java ReadFilter
This is a text file
C:\nisha>
No comments:
Post a Comment