Java FileInputStream Class


In Java language, FileInputStream is used for reading data from the files.

public class FileInputStream extends InputStream 

FileInputStream class methods

S.No Method Description
1 protected void finalize()throws IOException {} This method is used to cleans up the connection to the file.
2 public int available() It is used to return the number of bytes that can be read from the input stream.
3 public void read(byte[] a) It is used to read a.length bytes from the input stream into an array. It is returns the total number of bytes read.
4 public void read(int a) It is used to read the specified byte of data from the file Input stream.
5 public void close() This method is used to closes the file output stream.

Example:

import java.io.*;
public class FileOutputStreamDemo{
    public static void main(String args[]){  
        try {
         	FileInputStream in = new FileInputStream("Inp.txt");
            int i=0;    
            while((i=in.read())!=-1){    
				System.out.print((char)i);    
            }  
        }catch(Exception e){
            System.out.println(e);
        }   
        finally {
			in.close();
        }
    }
}

Output

 Welcome



OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.