CIS 35A: Introduction to Java Programming

Home | Green Sheet | Lectures | Assignments | FAQ | Grades

Files

Text and Binary Files
Binary files
Connect a binary input stream to a file

A subset of the InputStream hierarchy

InputStream {abstract}
    FileInputStream
    FilterInputStream
        BufferedInputStream
        DataInputStream {implements DataInput interface}

Notes

  • All classes in the java.io and java.util.zip packages that end with InputStream are members of the InputStream hierarchy.
  • The FilterInputStream class is a superclass of all classes that filter binary input streams.

Classes used to connect a binary input stream to a file

DataInputStream	reads data from the stream
	->BufferedInputStream	creates a buffer for the stream
		->FileInputStream	connects the stream to the file

Constructors of these classes

Constructor Throws
DataInputStream(InputStream) None
BufferedInputStream(InputStream) None
FileInputStream(File) FileNotFoundException
FileInputStream(StringFileName) FileNotFoundException

How to connect a binary input stream to a file

DataInputStream in = new DataInputStream(
                     new BufferedInputStream(
                     new FileInputStream(productsFile)));
Previous | Binary I/O | Connect a binary output stream to a file | Write to a binary file | Connect a binary input stream to a file | Read from a binary file | Two ways with binary strings | Next