File
object to exist without a file?
File
object?
File
Constructors
Here is one of the constructors for File
:
// Construct a File object for a file // with name pathName. File( String pathName )
The path name of a file is a sequence of directory names followed by a file name.
The directory names are separated by a special character.
The syntax for directory names, separators, and
file names depends on the operating system.
When the program stops running, the File
object no longer exists,
but the file remains on disk (unless the program deliberately deleted it).
Here is a path name for a MS Windows file:
C:\MyFiles\Programs\someFile.txt
The directory separator character (for MS Windows) is "\". The last part of the path name, following the last separator, is the file name. Here is a Unix path name:
/usr/frodo/Programs/someFile.txt
Path names are relative or absolute.
An absolute path name gives the complete sequence of
directories from the root directory to the file.
A relative path name starts with any directory
in the sequence and continues to the file name.
Both relative and absolute path names may be
used with the File
constructor.
Is the following a correct use of a constructor?
File progFile = new File( "C:\MyFiles\Programs\Examples\someFile.txt" );