Read data from text file with java



User Rating:  / 1
PoorBest 
Details
Category: Java
Created on Sunday, 29 April 2012 07:30
Last Updated on Thursday, 03 May 2012 14:02
Published on Sunday, 29 April 2012 07:30
Written by Administrator
Hits: 7329

Read data from text file with java and write to screen :

View source
/*
 * www.Developerpages.gr
 * Read data from text file
 */
package readfromfile;
 
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
 
 
public class ReadFromFile {
 
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       String fileLine;
        
        try {
            FileReader inputFile = new FileReader("test.txt");
            BufferedReader bufReader = new BufferedReader(inputFile);
            try {
                while (( fileLine = bufReader.readLine()) != null){
                    System.out.println(fileLine);
                }
            } catch (IOException ex) {
                Logger.getLogger(ReadFromFile.class.getName()).log(Level.SEVEREnull, ex);
            }
           
        } catch (FileNotFoundException ex) {
            Logger.getLogger(ReadFromFile.class.getName()).log(Level.SEVEREnull, ex);
        }
        
        
    }
}
 

file test.txt   :

www.developerpages.gr
---------------------
Read Test data from text file

Run program :