Using Java’s Character-Based Streams

As the preceding sections have shown, Java’s byte streams are both powerful and flexible. However, they are not the ideal way to handle character-based I/O. For this purpose, Java defines the character stream classes. At the top of the character stream hierarchy are the abstract classes Reader and Writer. Table 10-7 shows the methods in Reader, and Table 10-8 shows the methods in Writer. Most of the methods can throw an IOException on error. The methods defined by these two abstract classes are available to all of their subclasses. Thus, they form a minimal set of I/O functions that all character streams will have.

Table 10-7 The Methods Defined by Reader

Table 10-8 The Methods Defined by Writer

Console ...

Get Java, A Beginner's Guide, 5th Edition, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.