logo

APSU Notes


Chapter 10 Summary

  • Files that are considered to be strings of characters and that look like characters to your program and to a text editor are called text files. All other files are called binary files.
  • Your program can use the class PrintWriter to write to a text file and can use the class Scanner to read from a text file.
  • When reading from a file, you should always check for the end of a file and do something appropriate if the end of the file is reached. The way you test for the end of a file depends on whether your program is reading from a text file or a binary file.
  • You can read a file name from the keyboard into a variable of type String and use that variable in place of a file name.
  • The class File can be used to see whether an existing file has a given name. It can also be used to see whether your program is allowed to read the file or write to the file.
  • Your program can use the class ObjectOutputStream to write to a binary file and can use the class ObjectInputStream to read from a binary file.
  • Your program can use the method writeObject of the class ObjectOutputStream to write class objects or arrays to a binary file. Objects or arrays can be read from a binary file using the method readObject of the class ObjectInputStream.
  • In order to use the methods writeObject of the class ObjectOutputStream and readObject of the class ObjectInputStream, the class whose objects are written to a binary file must implement the Serializable interface.
  • You can connect a PrintWriter or Scanner to a socket to read and write data over a network.