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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access