chapter15 - 1 Chapter 15 Files I/O basics File I/O Classes...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 Chapter 15 Files I/O basics File I/O Classes File I/O Basic Operations Text File Output PrintWriter import Statement with a * Text File Input Scanner , FileReader HTML File Generator Text Format Versus Binary Format Binary I/O Output with: DataOutputStream, FileOutputStream Input with: DataInputStream, FileInputStream Object I/O Output with: ObjectOutputStream , FileOutputStream Input with: ObjectInputStream , FileInputStream 1 2 I/O Basics So far, all input has come from the keyboard and all output has been to the console window. Keyboard and console input/output (I/O) is temporary, not permanent. For permanent I/O, use files. Benefit of reading input from a file: Allows input to be reused without having to re-enter the input via the keyboard. Benefits of saving output to a file: Allows output to be re-viewed without having to rerun the program. Allows program chaining where the output of one program is used as the input for another program. 1 2 3 File I/O Classes For programs that manipulate files, you'll need to use several pre- built classes from the Java API library. The Java API is organized as a hierarchy of packages where each package contains a group of classes. Here's the file I/O portion of the Java API library: 1 2 3 4 5 6 DataInputStream DataOutputStream File FileNotFoundException FileInputStream FileOutputStream FileReader FileWriter IOException ObjectInputStream ObjectOutputStream PrintWriter the root of the java package tree packages classes java.lang holds the basic classes (e.g., Math , String ) and is automatically imported . java.lang java java.util java.io ... Scanner 4 File I/O Classes There are lots of classes that deal with file I/O, and there's overlap with some of those classes. In other words, some classes handle the same sort of file operation(s). The book covers the file I/O classes that are the easiest to use. Here are the file I/O classes that the book covers: 1 2 3 If you want to write text to a file, use the PrintWriter class. If you want to read text from a file, use the Scanner and FileReader classes. If you want to write objects to a file, use the ObjectOutputStream and FileOutputStream classes. If you want to read objects from a file, use the ObjectInputStream and FileInputStream classes....
View Full Document

This note was uploaded on 10/22/2010 for the course COMPSCI CS201 taught by Professor Sorenson during the Spring '10 term at Wisconsin Milwaukee.

Page1 / 31

chapter15 - 1 Chapter 15 Files I/O basics File I/O Classes...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online