19.5 Reading from Files and Writing to Files
To read data from files or write data to files, a stream class is needed that manages the mapping of the abstract methods of Reader, Writer, InputStream, and OutputStream to files. To carry out such implementations, three different approaches are available:
-
The Files utility class provides some new*(...) methods that enable read/write data streams for character- and byte-oriented files.
-
A Class object provides getResourceAsStream(...) and returns an InputStream that reads bytes from files in the module path. For writing, no comparable method exists. If Unicode characters must be read, the InputStream must be converted to a Reader .
-
The special classes FileInputStream, FileReader, FileOutputStream ...
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