by Dinesh Thakur Category: Stream

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) {}
       }
}

Reading Data From File

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Search Content







Popular Article