Home » Java » Read files in java

Read files in java

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

public class ReadFile {

    public static void main(String[] args) throws FileNotFoundException {
      
        File file = new File("file_path");
        FileReader fileReader = new FileReader(file);
        BufferedReader buffuredReader = new BufferedReader(fileReader);
        String data = "";
        try {
            while((data = buffuredReader.readLine()) != null){
                System.out.println(data);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }    
    }
}
Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*