728x90 AdSpace

Wednesday, 2 October 2013

Read File using BufferedReader



In this tutorials we are going to see how to read file using BufferedReader.
Create project called JavaMisc.
Create package called com.javatutorialscorner.io Create java class called FileReaderExample under com.javatutorialscorner.io package.
FileReaderExample.java
package com.javatutorialscorner.io;

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

public class FileReaderExample {

public static void main(String[] args) {

FileReader fr = null;

BufferedReader br = null;
try {
fr = new FileReader("C:\\jtc\\javatutorialscorner.txt");
br = new BufferedReader(fr);
String tempLine;

while ((tempLine = br.readLine()) != null) {
System.out.println(tempLine);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {

try {
if (br != null) {
br.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}

}


Now run the program see the following output in console.
this is test file created by java tutorials corner
This content read from input file
Annamalai Thangaraj

Annamalai is a Software Engineer with 3+ years experience in Java, Spring, Struts, Hibernate, IDM/IAM, and Enterprise Web Application Development.

Website: Java Tutorials Corner

  • Blogger Comments
  • Facebook Comments
  • Disqus Comments

0 comments:

Post a Comment

Item Reviewed: Read File using BufferedReader Rating: 5 Reviewed By: Annamalai Thangaraj