Chapter 14 - Files, Streams, and Input/Output Techniques

Chapter Objectives:

  • Be able to read and write text files.
  • Know how to read and write binary files.
  • Understand the  use of InputStreams and OutputStreams
  • Be able to design methods for performing input and output. 
  • Know how to use the File class.
  • Be able to use the JFileChooser class.

Download PPT slides

Index:


 

Introduction

Streams and Files

Binary Files versus Text Files

Class Description
InputStream Abstract root class of all binary input streams
File Provides platform independent methods for dealing with files and directories
FileInputStream Provides methods for reading bytes from a binary file
BufferedInputStream Provides input data buffering for reading large files
DataInputStream Provides methods for reading Java's primitive data types
OutputStream Abstract root class of all binary output streams
FileOutputStream Provides methods for writing bytes to a binary file
BufferedOutputStream Provides output data buffering for writing large files
DataOutputStream Provides methods for writing Java's primitive data types
Reader Abstract root class for all text input streams
BufferedReader Provides buffering for character input streams
FileReader Provides methods for character input on files
StringReader Provides input operations on Strings
Writer Abstract root class for all text output streams
BufferedWriter Provides buffering for character output streams
FileWriter Provides methods for output to text files
PrintWriter Provides methods for printing binary data as characters
StringWriter Provides output operations to Strings
Table 14-1 Important Stream Classes
 
 

Buffering and Filtering

Text based data files

Text based report files

File Class

Command Line Arguments

Reading and Writing Objects

JFileChooser

  • To use the JFileChooser object to prompt the user for a file name you must:


  • Advanced example:



    Other Notes:


    Summary:


    Keywords: absolute path name, buffering, buffer, binary file, command-line argument, database, data hierarchy, directory, end-of-file character, field, file, filtering,input stream, output stream, path, platform independent, record,relative path name, serialization, stream, text file, UTF
     

    Suggested Excercises: 1, 2, 3, 4, 7, 8, 12, 15, 17, 18