We are moved to new domain
Click -> www.ehowtonow.com
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

Shop and help us

Flipkart Offer Snapdeal offer Amazon.in offer Amazon.com offer
  • Blogger Comments
  • Facebook Comments
  • Disqus Comments

0 comments:

Post a Comment

Item Reviewed: Read File using BufferedReader Rating: 5 Reviewed By: eHowToNow