Java Tutorial - Java Script : BufferedReader:

Java Tutorial - Java Script :

BufferedReader

·         BufferedReader(Reader)—Creates a buffered character stream associated with the specified Reader object, such as FileReader
·         BufferedReader(Reader, int)—Creates a buffered character stream associated with the specified Reader and with a buffer of int size

A buffered character stream can be read using the read() and read(char[], int, int) methods described for FileReader. You can read a line of text using the readLine() method.
The readLine() method returns a String object containing the next line of text on the stream, not including the character or characters that represent the end of a line. If the end of the stream is reached, the value of the string returned will be equal to null. An end-of-line is indicated by any of the following:

·         A newline character (‘\n’)
·         A carriage return character (‘\r’)
·         A carriage return followed by a newline (“\n\r”)

The project contained in Listing 15.7 is a Java application that reads its own source file through a buffered character stream.
Much of this program is comparable to projects created earlier today, as illustrated:
·         Lines 6–7—An input source is created: the FileReader object associated with the file SourceReader.java.
·         Lines 8–9—A buffering filter is associated with that input source: the BufferedReader object buff.
·         Lines 11–17—A readLine() method is used inside a while loop to read the text file one line at a time. The loop ends when the method returns the value null.
The SourceReader application’s output is the text file SourceReader.java.