Share on Google+Share on Google+

How To Read File In Java with BufferedReader

Tutorial teaches you How To Read File In Java with BufferedReader?

How To Read File In Java with BufferedReader class - example code

This tutorial shows you how you can read file using BufferedReader class in your program. This tutorial is using the BufferedReader class for reading simple text file. The BufferedReader class provides added benefits of increasing the performance of the application.

Our program is simple program that reads a text file line by line.

Program prints the content of the file on console.

Here is the complete code of the program for reading file with BufferedReader class:

* How To Read File In Java with BufferedReader class
public class ReadUsingBufferedReader 
	public static void main(String[] args) 
		System.out.println("Reading File with BufferedReader class");
		//Name of the file
		String fileName="test.text";
		//Create object of FileReader
		FileReader inputFile = new FileReader(fileName);
		//Instantiate the BufferedReader Class
		BufferedReader bufferReader = new BufferedReader(inputFile);

		//Variable to hold the one line data
		String line;
		// Read file line by line and print on the console
		while ((line = bufferReader.readLine()) != null)   {
			System.out.println("File Line is: " + line);
		//Close the buffer reader
		}catch(Exception e){
			System.out.println("Error in reading file:" + e.getMessage());			


Posted on: January 20, 2013 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: How To Read File In Java with BufferedReader  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image