- File/Console I/O -


The zio package supports two kinds of File or Console I/O.

  1. Whole file I/O with

    InOut.readText, InOut.writeText,  InOut.readImage, and InOut.writeImage

    These methods are simple to understand and use. You can go very quickly over the I/O ground with them.

    Of course, once you have read an entire file, separating it into useful chunks can be a problem. This, however, is an algorithmic problem and fits well with an emphasis on algorithms. Also, the Zio class has methods that take a string generated by InOut.readText() and make return an array of lines or an array of tokens from it. Students must know about arrays to use these methods. That can be a good thing. Arrays are important.

    If you are teaching a high school AP class, notice that to deemphasize I/O is to emphasize things that are on the exam.

    If you use this approach, you will probably want some rudimentary console I/O as well. and Zio.abort provide this.

  2. Traditional I/O (that means char by char, line by line, int by int, double by double, or token by token) with the Input and Output classes. With these classes you can use the same methods for file I/O as for console I/O.

    Whereas the whole file approach has students doing things with arrays of lines or arrays of tokens (and so on), this approach has students using an I/O loop in a traditional manner.

    The attraction here is that you could teach a course that is very similar to what has been taught for the past three decades. Or, at least, you could start out that way. If you also teach advanced courses, you could use Input and Output for text I/O between sockets.

One thing that all these I/O methods have in common is that they are not overloaded in a way that lets students confuse which data type they are working with. Students will either be working with methods, such as readInt, that explicitly say what data type they work with or they will be dealing with methods that work with Strings.

contextJul 8, 2005author