BufferedReader Class
Package: java.io
Reads text from a character input stream, buffering the input to provide efficient reading.
Constructor
Constructor |
Description |
|
Creates a buffered reader from any object that extends the |
Methods
Method |
Description |
|
Closes the file and throws |
|
Reads a single character from the file and returns it as an integer. The method returns |
|
Reads an entire line and returns it as a string. The method returns |
|
Skips ahead the specified number of characters. |
Creating a BufferedReader
A BufferedReader
is usually created from a FileReader
, which is in turn created from a File
, like this:
File f = new File(“myfile.txt”);
BufferedReader in;
in = new BufferedReader(new FileReader(f));
Reading from a BufferedReader
To read a line from a BufferedReader
, you use the readLine
method. This method returns null
when the end of the file is reached. As a result, testing the string returned ...
Get Java For Dummies Quick Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.