FileInputStream is a is present in java.io package and is the child class of InputStream class. It reads data in the form of bytes from a text file.
FileInputStream file = new FileInputStream(“Hello.txt”) ; Here file is the object of FileInputStream class and points to “Hello.txt” file and if the file is not present then program is terminated by generating fileNotFoundException.
Read data from the file.
Here is the Java Example for Reading Data From File:
import java.io.*;
class ReadDataFile
{
public static void main(String args[])
{
try
{
FileInputStream file=new FileInputStream("Hello.txt");
System.out.println("Show the File Contents ");
int ch;
while((ch=file.read())!=-1)
System.out.print((char)ch);
file.close();
}
catch(IOException e) {}
}
}