Search Here

Java program for Reading a text File


/* Reading a file */

import java.io.*;
class Main
{
 public static void main(String args[])
 {
  FileInputStream fstream;
  DataInputStream in;
  
  try
  {
   fstream=new FileInputStream("A.txt");
   in=new DataInputStream(fstream);
   System.out.println("File content is: ");
   while(in.available()!=0)
   {
    String st=in.readLine();
    System.out.print(st);
   }
   in.close();
  }
  catch(Exception e)
  {
   System.err.println(e);
  }
 }
}

No comments:

Post a Comment