CIS 35A: Introduction to Java Programming

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

Files

Text and Binary Files
File input and output
Files and streams

How files and streams work

  • An input file is a file that is read by a program.
  • An output file is a file that is written by a program.
  • Input and output operations are often referred to as I/O operations or file I/O.
  • A stream is the flow of data from one location to another.
  • To write data to a file from internal storage, you use an output stream.
  • To read from a file into internal storage, you use an input stream.
  • To read and write text files, you use character streams.
  • To read and write binary files, you use binary streams.
  • Streams are not only used with disk devices, but also with input devices like keyboards and network connections and output devices like PC monitors and network connections.

A text file that's opened by a text editor

A binary file that's opened by a text editor

Two types of files

File Description
Text A file that contains characters. The fields and records in this type of file are often delimited by special characters like tab and new line characters.
Binary A file that may contain characters as well as other non-character data types that can't be read by a text editor.

Two types of streams

Stream Description
Character Used to transfer text data to or from an I/O device.
Binary Used to transfer binary data to or from an I/O device.
Previous | Files and streams | File I/O | I/O exceptions | Next