# Java: BufferedReader/Writer

## `BufferedReader` and `BufferedWriter` methods

java.io.BufferedReader and java.io.BufferedWriter are used to read/write Strings from/to text files. Assume br is a BufferedReader, bw is a BufferedWriter, and f is a File object.

Constructors -- see examples
br = | new BufferedReader(new FileReader(f));
bw = | new BufferedWriter(new FileWriter(f));
BufferedReader Methods
s = | br.readLine() | Returns next input line without newline char(s) or null if no more input. May throw IOException.
s = | br.close() | Close when finished reading to unlock file.
BufferedWriter Methods
| bw.writeLine(s) | Writes s to file without newline char(s). May throw IOException.
| bw.newLine() | Writes operating-system dependent newline (CR, LF, or CRLF).
| bw.close() | Call `close()` when finished writing, otherwise data may not be written to disk.

## Example

See File I/O - Text Files for an example of reading and writing text files.