Read data from myfile.txt using FileInputStream and display on the monitor. - LearnHowToCode SarkariResult.com Interview Questions and Answers LearnHowToCodeOnline
Read data from myfile.txt using FileInputStream and display on the monitor.

Read data from myfile.txt using FileInputStream and display on the monitor.

// There Reading the text file FileInputStream:

import java.io.*;
class ReadFile
{
public static void main(String[]arr)
throws IOException
{
// attch  the file to FileInputStream
FileInputStream fin=new FileInputStream("myfile.txt");
System.out.println("FileContents:");
     // raed Character from FileInputStream and write them

   //to monitor .Repeat this till the end of file,
int ch;
              while(( ch=fin.read())!=-1)
      System.out.print((char)ch);
// close the file
      fin.close();
}
}

That is Output

E:\ShashiJava>javac ReadFile.java
E:ShashiJava>java ReadFile
This is my file line one
This is my file line two 
Hello I am Shahsi This File No Is One


Hello I am Shahi This File No Is Two

About EasyToCode

I'm Ethan Mariano a software engineer by profession and reader/writter by passion.I have good understanding and knowledge of AngularJS, Database, javascript, web development, digital marketing and exploring other technologies related to Software development.

0 comments:

Featured post

Political Full Forms List

Acronym Full Form MLA Member of Legislative Assembly RSS Really Simple Syndication, Rashtriya Swayamsevak Sangh UNESCO United Nations E...

Powered by Blogger.