Latest News

Thursday, September 29, 2016

How to read .txt file in java?


To read the file you can use buffered reader class.



Example:


public class ReadFromBufferReader {

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

   File fl = new File("d:/myfile.txt");//path of your text file

   BufferedReader br = new BufferedReader(new FileReader(fl)) ;
   String str;
   while ((str=br.readLine())!=null)
   {
    System.out.println(str);
   }
   br.close();

  }


}