23.07.2013 Views

Java IO.pdf - Nguyen Dang Binh

Java IO.pdf - Nguyen Dang Binh

Java IO.pdf - Nguyen Dang Binh

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

default:<br />

}<br />

}<br />

StreamCopier.copy(in, out);<br />

in.close();<br />

}<br />

}<br />

<strong>Java</strong> I/O<br />

Note how little I had to change to add support for compressed files. I simply imported one<br />

package and added a couple of command-line switches and six lines of code (which could<br />

easily have been two) to test for the command-line arguments and add one more filter stream<br />

to the chain. Zip and JAR files would not be hard to support either. You'd just have to iterate<br />

through the entries in the archive and dump each entry onto System.out. That's left as an<br />

exercise for the reader.<br />

192

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!