728x90 AdSpace

Latest Article

File Reading Example Code in Java | java.io FileReader BufferedReader




How to read file line by line in Java How to read and write in text file in Java Java File Reading and Writing Files in Java Reading a text file in Java


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class FileReadExample {
    public static void main(String[] args) {
        try {
            FileReader fro = new FileReader("C:\\myFile.txt");
            BufferedReader bro = new BufferedReader(fro);
            String strline=bro.readLine();
            String stringFromFile ="";
            while( strline!= null ) // end of the file       
            {
                stringFromFile+= strline;
                strline= bro.readLine( );// read next line  
            }
            System.out.println(stringFromFile); 
            bro.close( );
        }
        catch( FileNotFoundException filenotfoundexp ){
             System.out.println( "myFile.txt, does not exist" );
        }
        catch(IOException ioexception){
             ioexception.printStackTrace( );
        }
    }
}

no image
  • Title : File Reading Example Code in Java | java.io FileReader BufferedReader
  • Posted by :
  • Date : 00:53
  • Labels :





  • Blogger Comments
  • Facebook Comments

0 comments:

Post a Comment

Top