Monday 14, Apr 2025
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
01.package com.javatutorialscorner.io;
02. 
03.import java.io.BufferedReader;
04.import java.io.FileReader;
05.import java.io.IOException;
06. 
07.public class FileReaderExample {
08. 
09. public static void main(String[] args) {
10. 
11.  FileReader fr = null;
12. 
13.  BufferedReader br = null;
14.  try {
15.   fr = new FileReader("C:\\jtc\\javatutorialscorner.txt");
16.   br = new BufferedReader(fr);
17.   String tempLine;
18. 
19.   while ((tempLine = br.readLine()) != null) {
20.    System.out.println(tempLine);
21.   }
22.  } catch (IOException e) {
23.   // TODO Auto-generated catch block
24.   e.printStackTrace();
25.  }finally {
26. 
27.   try {
28.    if (br != null) {
29.     br.close();
30.    }
31.   } catch (IOException e) {
32.    // TODO Auto-generated catch block
33.    e.printStackTrace();
34.   }
35.  }
36. 
37. }
38. 
39.}


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

Related Posts:

  • Blogger Comments
  • Facebook Comments
  • Disqus Comments

0 comments:

Post a Comment

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