Home Java Example Java Io BufferedReader in Java

Related Tutorials


 
 

Share on Google+Share on Google+

BufferedReader in Java

Advertisement
BufferedReader in Java is used to to read characters, arrays, lines and File Line by line. It also reads text from a character-input stream. A programmer can change the buffer size or can use default size.

BufferedReader in Java is used to to read characters, arrays, lines and File Line by line. It also reads text from a character-input stream. A programmer can change the buffer size or can use default size.

BufferedReader class in Java is also used to read the data in buffer. Here we will show how to read line by line data from a file using BufferedReader.

BufferedReader Constructor:

BufferedReader in = new BufferedReader(new FileReader(f));

BufferedReader Methods

  • readLine() - This methods reads line of text
  • read() - This method reads and returns one character
  • read(char[] cbuf, int off, int len) - This method reads character into a portion of an array.
  • skip() - This method skips character.

Following is the example of BufferedReader in Java to read line:

import java.io.*;

public class BufferedReaderDemo {
public static void main(String[] args) {
try {
BufferedReader br = new BufferedReader(
new FileReader("DevFile.txt"));
String devstr;
while ((devstr = br.readLine()) != null) {
System.out.println(devstr);
}
} catch (IOException e) {
}
}
}

Output:

Welcome To Devmanuals
Here you find the good learning stuff.
As well complete coverage on each topics like java, PHP etc.

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  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.

Posted on: May 11, 2013

Related Tutorials

Discuss: BufferedReader in Java  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com