Menu
Topics Index
...
`

FilterInputStreamDemo - Java Example Program


FilterInputStreamDemo
import java.io.*;

class FilteredInputStreamDemo
{
    public static void main(String[] args) throws IOException
    {
        File f = new File("E:/JavaPrograms/FolderOne/fileOne.txt");
        if(f.exists())
            System.out.println("File exists.");
        else
            System.out.println("No file found.");
         FilterInputStream fis = new BufferedInputStream(new FileInputStream(f)); // LINE A
        
         int i;
         System.out.println("Available bytes : "+ fis.available()); // LINE B
         System.out.println("Mark Supported : " + fis.markSupported()); // LINE C
         while ( (i = fis.read()) != -1) // LINE D
         {
             System.out.print((char)i);
         }
         fis.close();// LINE E
    }
}
OUTPUT

File exists.
Available bytes : 12
Mark Supported : true
MERIT CAMPUS

DESCRIPTION

At LINE A we created a FilterInputStream reference for BufferedInputStream Object.
At LINE B we are checking the no. of bytes in the file.
At LINE C we are checking whether the file is markSupported.
At LINE D we are reading data from file.
At LINE E we are closing the stream.

THINGS TO TRY
  • Create a file and Write I LOVE PROGRAMMING in to it.
  • Set mark at P in the file and set limit as 3 and reset the file.
  • Inovoke any method after closing the stream to see an java.io.IOException.

© meritcampus 2019

All Rights Reserved.

Open In App