Java Character Stream BufferedReader/BufferedWriter
BufferedReader Constructors
| Constructor | Description |
|---|---|
| BufferedReader(Reader in) | Creates an object with a default-size buffer for the given character input stream in. |
| BufferedReader(Reader in, int size) | Creates an object with a buffer of size for the given character input stream in. |
BufferedReader Methods
BufferedReader basically inherits and uses Reader methods.
| Method | Description |
|---|---|
| String readLine() | Reads one line. It reads until it meets a newline character(’\n’, ‘\r’). |
Using the readLine() method makes character reading more efficient. It is easier to process by reading one line at a time than by reading one character at a time with the existing read() method.
BufferedReader Example
Preparing.
BufferedWriter Constructors
| Constructor | Description |
|---|---|
| BufferedWriter(Writer out) | Creates an object with a default-size buffer for the given character output stream out. |
| BufferedWriter(Writer out, int size) | Creates an object with a buffer of size for the given character output stream out. |
BufferedWriter Methods
BufferedWriter basically inherits and uses Reader methods.
| Method | Description |
|---|---|
| void newLine() | Changes the line. |
When a line break is needed while outputting characters, you can use the newLine() method in the buffer to create a line break.
BufferedWriter Example
Preparing.