OBJECT ORIENTED
PROGRAMMING
Streams and Files
Salvatore Distefano
,Introduction
■ Data stored in variables and arrays is temporary
§ It’s lost when a local variable goes out of scope or when the program terminates
■ For long-term retention of data, computers use files.
■ Computers store files on secondary storage devices
§ hard disks, flash drives, DVDs and more.
■ Data maintained in files is persistent data because it exists beyond the duration of
program execution.
,Files and Streams
■ Java views each file as a sequential stream of bytes (Fig. 15.1).
■ Every operating system provides a mechanism to determine the end of a file, such as an
end-of-file marker or a count of the total bytes in the file that is recorded in a system-
maintained administrative data structure.
■ A Java program simply receives an indication from the operating system when it reache
the end of the stream
,
PROGRAMMING
Streams and Files
Salvatore Distefano
,Introduction
■ Data stored in variables and arrays is temporary
§ It’s lost when a local variable goes out of scope or when the program terminates
■ For long-term retention of data, computers use files.
■ Computers store files on secondary storage devices
§ hard disks, flash drives, DVDs and more.
■ Data maintained in files is persistent data because it exists beyond the duration of
program execution.
,Files and Streams
■ Java views each file as a sequential stream of bytes (Fig. 15.1).
■ Every operating system provides a mechanism to determine the end of a file, such as an
end-of-file marker or a count of the total bytes in the file that is recorded in a system-
maintained administrative data structure.
■ A Java program simply receives an indication from the operating system when it reache
the end of the stream
,