Chapter Summary


[Page 551 (continued)]

Technical Terms

absolute path name

binary file

buffering

database

data hierarchy

directory

end-of-file character

field

file

filtering

input

object serialization

output

path

record

relative path name

Unicode Text Format (UTF)

Summary of Important Points

  • A file is a collection of data stored on a disk. A stream is an object that delivers data to and from other objects.

  • An InputStream is a stream that delivers data to a program from an external source, such as the keyboard or a file. System.in is an example of an InputStream. An OutputStream is a stream that delivers data from a program to an external destination, such as the screen or a file. System.out is an example of an OutputStream.

  • Data can be viewed as a hierarchy. From highest to lowest, a database is a collection of files. A file is a collection of records. A record is a collection of fields. A field is a collection of bytes. A byte is a collection of eight bits. A bit is one binary digit, either 0 or 1.

  • A binary file is a sequence of 0s and 1s that is interpreted as a sequence of bytes. A text file is a sequence of 0s and 1s that is interpreted as a sequence of characters. A text file can be read by any text editor, but a binary file cannot. InputStream and OutputStream are abstract classes that serve as the root classes for reading and writing binary data. Reader and Writer serve as root classes for text I/O.

  • Buffering is a technique in which a buffer, a temporary region of memory, is used to store data during input or output.

  • A text file contains a sequence of characters divided into lines by the \n character and ending with a special end-of-file character.

  • The standard algorithm for performing I/O on a file consists of three steps: (1) open a stream to the file, (2) perform the I/O, and (3) close the stream.


  • [Page 552]
  • Designing effective I/O routines answers two questions: (1) What streams should I use to perform the I/O? (2) What methods should I use to do the reading or writing?

  • To prevent damage to files when a program terminates abnormally, streams should be closed when they are no longer needed.

  • Most I/O operations generate an IOException that should be caught in the I/O methods.

  • Text input uses a different technique to determine when the end of a file has been reached. Text input methods return null or -1 when they attempt to read the special end-of-file character. Binary files do not contain an end-of-file character, so binary read methods throw an EOFException when they attempt to read past the end of the file.

  • The java.io.File class provides methods that enable a program to interact with a file system. Its methods can be used to check a file's attributes, including its name, directory, and path.

  • Streams can be joined together to perform I/O. For example, a DataOutputStream and a FileOutputStream can be joined to perform output to a binary file.

  • A binary file is "raw" in the sense that there are no markers within it that allow you to tell where one data element ends and another begins. The interpretation of binary data is up to the program that reads or writes the file.

  • Object serialization is the process of writing an object to an output stream. Object deserialization is the reverse process of reading a serialized object from an input stream. These processes use the java.io.ObjectOutputStream and java.io.ObjectInputStream classes.

  • The JFileChooser class provides a dialog box that enables the user to select a file and directory when opening or saving a file.




Java, Java, Java(c) Object-Orienting Problem Solving
Java, Java, Java, Object-Oriented Problem Solving (3rd Edition)
ISBN: 0131474340
EAN: 2147483647
Year: 2005
Pages: 275

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