138. Reading/writing text files efficiently

In Java, reading files efficiently is a matter of choosing the right approach. For a better understanding of the following example, let's assume that our platform's default charset is UTF-8. Programmatically, the platform's default charset can be obtained via Charset.defaultCharset().

First, we need to distinguish between raw binary data and text files from a Java perspective. Dealing with raw binary data is the job of two abstract classes, that is, InputStream and OutputStream. For streaming files of raw binary data, we focus on the FileInputStream and FileOutputStream classes, which read/write a byte (8 bits) at a time. For famous types of binary data, we also have dedicated classes (for example, ...

Get Java Coding Problems now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.