Register Now

Login

Lost Password

Enter your email to reset your password.

BY Author

Java – The FileInputStream class

The FileInputStream class is used to read data in the form of bytes.

Declaration

class FileInputStream extends InputStream

Constructors of FileInputStream (CLICK HERE)

Methods defined in FileInputStream (CLICK HERE)

Example

Let’s assume that text file “xyz.txt” is present in the current working dictionary.

Java Programming Language FileInputStream Class in File Handling

 import java.io.FileInputStream;
 import java.io.IOException;

 class FileInputStreamDemo 
 {
     public static void main(String args[]) throws IOException
     {
         FileInputStream f = new FileInputStream("xyz.txt");
         System.out.println("Total Available Bytes :: "+f.available());
         int i = f.read();
         while(i!=-1)
         {
             System.out.print((char)i);
             i = f.read();
         }
         System.out.println("\n Total Available Bytes :: "+f.available());
         f.close();	
     }
 } 

Output

Total Available Bytes :: 19
Java is very Simple
Total Available Bytes :: 0

Total available bytes are 19 (including space).

 

Leave a reply