21.2. Motivations

 
[Page 630]

Chapter Summary

  • I/O can be classified into text I/O and binary I/O. Text I/O interprets data in sequences of characters . Binary I/O interprets data as raw binary values. How text is stored in a file is dependent on the encoding scheme for the file. Java automatically performs encoding and decoding for text I/O.

  • The InputStream and OutputStream classes are the roots of all binary I/O classes. FileInputStream / FileOutputStream associates a file for binary input/output. BufferedInputStream / BufferedOutputStream can be used to wrap on any binary I/O stream to improve performance. DataInputStream / DataOutputStream can be used to read/write primitive values and strings.

  • ObjectInputStream / ObjectOutputStream can be used to read/write objects in addition to primitive values and strings. To enable object serialization, the object's defining class must implement the java.io.Serializable marker interface.

  • The RandomAccessFile class enables you to read and write data to a file. You can open a file with the "r" mode to indicate that it is read-only, or with the "rw" mode to indicate that it is updateable. Since the RandomAccessFile class implements DataInput and DataOutput interfaces, many methods in RandomAccessFile are the same as those in DataInputStream and DataOutputStream .

 


Introduction to Java Programming-Comprehensive Version
Introduction to Java Programming-Comprehensive Version (6th Edition)
ISBN: B000ONFLUM
EAN: N/A
Year: 2004
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net