FileInputStream Class : Read data from File

File management is very useful part in java programs. In this blog, we will see FileInputStream class. This class uses of read data from any .txt, .bat, .java etc file from folder.

In this program, we will read data from demoTextFile.txt. Without this file we can’t run program. So first create this file near your java file.

Better understanding, we will see video first then move to our program.


Video on FileInputStream Class

Program on Read data from file


class io5


                public static void main(String args[]) throws IOException


                                FileInputStream fin = null;



                                                fin = new FileInputStream(“demoTextFile.txt”);                // in folder file

                                                //fin = new FileInputStream(“d:/folder/demoTextFile.txt”);       // in folder file

// How to read data from file

// use read() method


                                                int i;



                                                                i =;



                                                while(i!=-1);       // -1 => end of file



                                catch(Exception ex)







Display content from demoTextFile.txt [Check yourself]


If you have any query on blog example, you can directly comment us or subscribe our website

Earn Money Online

1301total visits,1visits today


Hello, I am Maddy a Java blogger, trainer and developer

Related articles

Comments are closed.