Title: Methods for reading and writing files
Course: CPS 189: Java Certification - Review, Practice & Prepare (Development) > Section: (OLDstyle) Learning Modules

Methods for reading and writing files

The following methods, from class java.nio.file.Files, are available for reading and writing files:

- readAllBytes – reads all bytes from a small file into an array.
- readAllLines – reads all lines from a small file into an array.
- write – writes all bytes/lines from an array to a small file.
- newBufferedReader – reads a file via a buffer.
- newBufferedWriter – writes a file via a buffer.
- newInputStream – reads a file without a buffer.
- newOutputStream – writes a file without a buffer.
- newByteChannel – reads from / writes to a file while controlling the position within the file.
- createFile – creates a file with default or specified attributes.
- createTempFile – creates a “temporary” file with default or specified attributes. Java does not automatically delete a temporary file.

For more information, see:

- Reading, Writing, and Creating Files
- Level 1 Study Materials: Unit 2
- Level 1 Study Materials: Unit 3