Next: Exceptions
Up: Unit 09
Previous: The concept of file
To execute reading and writing operations on a file, we must open the
file before doing the operations, and close it after we are finished
operating on it.
- Opening a file means to indicate to the operating system that we
want to operate on a file from within a Java program, and the operating
system verifies whether such operations are possible and allowed. There are
two ways of opening a file: opening for reading and opening for
writing, which cause a different behavior of the operating system. For
example, two files may be opened at the same time by two applications for
reading, but not for writing; or a file on a CD may be opened for reading,
but not for writing. In many programming languages (including Java), opening
a file for writing means actually to create a new file.
- Closing a file means to indicate to the operating system that
the file that was previously opened is not being used anymore by the program.
Closing a file also has the effect of ensuring that the data written on the
file are effectively transferred to the hard-disk.
Next: Exceptions
Up: Unit 09
Previous: The concept of file