Lesson 6: IO and the Java Class Library.

Overview

Java consists of a language called Java, an machine architecture called the Java Virtual Machine, and a large collection of API's. Official Java documentation is in the form of HTML pages, which are automatically generated from the code. The API for Input/Output is found in package java.io. In Java, Input/Output is represented and accessed through objects.

You must have the JDK documentation installed in C:\jdk1.1.6\docs to reference the links on this page.
Download the documentation and unzip into C:\jdk.1.16.

Java uses the stream concept for some of its IO. A stream is a sequence of characters or bytes, such as text being typed in or out of the console. The simplest I/O is a stream of bytes. These are represented by the abstract classes java.io.InputStream and java.io.OutputStream. Java defines a portable stream of Unicode characters. Unicode is a 16 bit universal character set which includes letters and symbols from all the world's languages, and is supported by Unicode organization. These streams are represented by abstract classes java.io.Reader and java.io.Writer.

Examples:

  1. CountBytes.java
  2. YoungerThan.java
  3. More.java

The details

At the foundation for raw byte I/O are the abstract classes InputStream and OutputStream. For text I/O, the foundation are the abstract classes Reader and Writer. These streams are either extended to implement streams coming from or going to specific places, such as the FileReader class ( a text stream coing from a file) or filtered to add additional functionality, such as the BufferedReader class which allows a text stream to be read line by line.

The File class is the basis for manipulating the file system.