Java I/O
Thorough guide to the java.(n)io API. Less useful as a cookbook as the organization of the book follows the API rather than focusing on specific tasks (e.g. how to best copy a file). Could have done without some of the cool chapters such as the one on J2ME (better treated in other books), or the one that describes hooking up a temperature sensor via USB, or a GPS via Bluetooth (publish these projects in a blog). Could also cut the rants about how outdated command line applications are, and I don't think the Swing-based file browser application that's built up throughout the book adds much. On the other hand I'd rather have more on performance considerations and error handling strategies!
Far better resources available
It covers a lot of topics but I did find it particularly helpful in any way. The idea of gathering all the information about I/O into one book to use as a single resource is nice, but this book doesn't do a good job. Not that much help in explaining things and no help at all as far as practical examples went. You will learn much more from general Java books and Google searches.
HAVE A CUP OF JAVA I/O!!
Howell do you know I/O? If you don't know it very well, then this book is for you. Author Elliote Rusty Harold, has done an outstanding job of writing a 2ndedition of a book that shows you the I/O tricks and techniques used by gurus and wizards of the Java world.
Harold, begins with an exploration of I/O in Java. Then, the author discusses the two most common targets of I/O, the filesystem and the network. Next, he discusses filter streams, which are Java's mechanism for processing data as you read or write rather than doing it after the fact. The author also discusses a completely new I/O model based on channels and buffers instead of streams. He continues by discussing operations on files themselves as distinct from the contents of those files. Then, the author explores how text is represented in Java and how it can be manipulated through special text streams called readers and writers. Finally, he shows you how to communicate with different kinds of peripherals and small devices that don't have traditional filesystems or network connections..
This most excellent book assumes you have a basic familiarity with Java. More importantly, this book is not a language tutorial, and the emphasis will always be on the I/O-specific features.
Pretty good coverage of NIO and practical crypto
Not a fan of O'Reilly books, but this one stands out because of excellent NIO coverage and topical examples. It beats the the "Java NIO" book from O'Reilly hands down. Overall I'd say this book is geared for those who want to implement but covers enough detail that it probably even soothes the more 'academic' out there (those who talk a good show but do not build real-world software).
Some highlights:
- You'll find good coverage of cryptographic I/O aimed at practical implementation.
- Excellent NIO coverage (including basic network servers in sync and async patterns)
- ZIP and JAR information including dynamic class loading
- Serial, USB and Bluetooth chapters (caveat: I don't use these but read them out of curiousity)
- Detailed coverage of readers/writers
- And obviously good coverage of the basic java.io/net packages.
As of Septemebr 2006 I find the book topical and current (even had some examples of future Java 6 code). To give you an idea of the detail offered here, there is a whole chapter (37 pages) of information on File access alone including pitfalls of cross-platform implementation. Not reading/writing files...just the trappings of opening and accessing files and directories using particular patterns, URLs, etc. The actual I/O is covered in similar depth in other chapters.
I'd also like to say that I highly appreciate examples that are concise and independant. There is nothing more frustrating than flipping to the middle of a book (what we all do anyway) and going through an example...only to find out that the author is using opaque references to classes and methods he/she developed on their own in five earlier chapters (bouncycastle APIs in Java Cryto for example). This pretty much makes quick-reference difficult to impossible and this book thankfully avoids it in spades.
I give it five starts because it'll be well used in several projects and because it is readable and accessible to both novice and advanced developers alike.
Great reference for your file input/output logic...
[Review of 2nd edition]
Getting data into and out of files in your Java program can be painstaking when you consider all the variations... network resources as files, compressed files, text vs. binary data in the file, etc. Java has significant power in this area, but there's a lot to know and understand. Elliotte Rusty Harold has made the task of learning it all a little easier with the book Java I/O (2nd edition).
Contents:
Part 1 - Basic I/O: Introducing I/O; Output Streams; Input Streams
Part 2 - Data Sources: File Streams; Network Streams
Part 3 - Filter Streams: Filter Streams; Print Streams; Data Streams; Streams in Memory; Compressing Streams; JAR Archives; Cryptographic Streams; Object Serialization
Part 4 - New I/O: Buffers; Channels; Nonblocking I/O
Part 5 - The File System: Working with Files; File Dialogs and Choosers
Part 6 - Text: Character Sets and Unicode; Readers and Writers; Formatted I/O with java.text
Part 7 - Devices: The Java Communications API; USB; The J2ME Generic Connection Framework; Bluetooth
Part 8 - Appendix: Appendix; Index
The first edition of this book was written back in 1999, and that's an eternity in computer years. Not only has the java.nio classes come into play since then, but you now have devices that were either bleeding edge or concept-only in 1999, like Bluetooth gadgets. Harold has improved the basic material to bring it up to date with the current state of Java development, and added the additional information for I/O classes through Java 6. I appreciated the large amount of coding samples that he uses to illustrate his points, as it makes it easy to adapt your learning to your own particular situation. The examples are also very focused, so you don't end up trying to filter out extraneous code to find the applicable concept you need.
There's another way to use this book that makes it even more valuable than just a reference manual. If you've been coding for awhile, it's possible that you've developed some ingrained approaches to file I/O that are outdated. By simply scanning the information here, you could easily find new ways to build your applications using newer methods. Or, you might find there are language features you didn't know existed, like the ability to write your files in a compressed format without having to go through a separate utility. Two or three personal revelations like that, and the book has quickly earned its place on the shelf.
While you may not use this book for every Java application you build, you'll definitely want it whenever you're working with I/O logic...