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.

Preface<br />

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

In many ways this book is a prequel to my previous book, <strong>Java</strong> Network Programming<br />

(O'Reilly & Associates). When writing that book, I more or less assumed that readers were<br />

familiar with basic input and output in <strong>Java</strong>—that they knew how to use input streams and<br />

output streams, convert bytes to characters, connect filter streams to each other, and so forth.<br />

However, after that book was published, I began to notice that a lot of the questions I got from<br />

readers of the book and students in my classes weren't so much about network programming<br />

itself as they were about input and output (I/O in programmer vernacular). When <strong>Java</strong> 1.1 was<br />

released with a vastly expanded java.io package and many new I/O classes spread out<br />

across the rest of the class library, it became obvious that a book that specifically addressed<br />

I/O was required. This is that book.<br />

<strong>Java</strong> I/O endeavors to show you how to really use <strong>Java</strong>'s I/O classes, allowing you to quickly<br />

and easily write programs that accomplish many common tasks. Some of these include:<br />

• Reading and writing files<br />

• Communicating over network connections<br />

• Filtering data<br />

• Interpreting a wide variety of formats for integer and floating-point numbers<br />

• Passing data between threads<br />

• Encrypting and decrypting data<br />

• Calculating digital signatures for streams<br />

• Compressing and decompressing data<br />

• Writing objects to streams<br />

• Copying, moving, renaming, and getting information about files and directories<br />

• Letting users choose files from a GUI interface<br />

• Reading and writing non-English text in a variety of character sets<br />

• Formatting integer and floating-point numbers as strings<br />

• Talking directly to modems and other serial port devices<br />

• Talking directly to printers and other parallel port devices<br />

<strong>Java</strong> is the first language to provide a cross-platform I/O library that is powerful enough to<br />

handle all these diverse tasks. <strong>Java</strong> I/O is the first book to fully expose the power and<br />

sophistication of this library.<br />

Correcting Misconceptions<br />

<strong>Java</strong> is the first programming language with a modern, object-oriented approach to input and<br />

output. <strong>Java</strong>'s I/O model is more powerful and more suited to real-world tasks than any other<br />

major language used today. Surprisingly, however, I/O in <strong>Java</strong> has a bad reputation. It is<br />

widely believed (falsely) that <strong>Java</strong> I/O can't handle basic tasks that are easily accomplished in<br />

other languages like C, C++, and Pascal. In particular, it is commonly said that:<br />

• I/O is too complex for introductory students; or, more specifically, there's no good<br />

way to read a number from the console.<br />

• <strong>Java</strong> can't handle basic formatting tasks like printing with three decimal digits of<br />

precision.<br />

1

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

Saved successfully!

Ooh no, something went wrong!