The UML of the File class includes:
_______________________________________ | File | |_______________________________________| | - String FileName | |_______________________________________| |constructor | | + File(String) | | + File(String,String) | | .... | | | |query | | + canRead() :boolean | | + canWrite() :boolean | | + exists() :boolean | | + getAbsolutePath() :String | | + isFile() :boolean | | + isDirectory() :boolean | | + length() :long | | .... | | | |mutator | | + createNewFile() :boolean | | + delete() :delete | | + deleteOnExit() :void | | + mkdir() :boolean | | + setToReadOnly() :void | | .... | |_______________________________________|
postcondition A new File object is created and, if possible, associated with the file named s AND Filename == s
public File(String s1,String s2)
postcondition A new File object is created and, if possible, associated with the file named s2 AND Filename == s2 with the location of the file in s1, either a complete path name or a relative name. s1 is said to be the parent of s2.
public boolean canRead()
output
result == true if and only if the file exists and it is permissible for the program to read from the file.
public boolean canWrite()
output
result == true if and only if the file exists and it is permissible for the program to write to this file.
public boolean exists()
output
result == true if and only if the file or directory identified by FileName already exists.
public String getAbsolutePath()
output
result == the complete name associated with FileName (even if the file does not exist)
public boolean isFile()
output
result == true if and only if a file identified by FileName already exists.
public boolean isDirectory()
output
result == true if and only if a directory identified by FileName already exists.
public long length()
output
if the exists() is true, result == the number of bytes occupied by the file/directory
AND if exists() is false, result == 0.
public boolean createNewFile()
postcondition
A new, empty file called FileName was created. (Note that any existing file with the same name in the same directory was lost, i.e., clobbered.)
output
result == the file creation was properly performed
public boolean delete()
precondition
exists() is true
postcondition
The file identified by FileName has been deleted from the system.
Output
result == the deletion was properly performed
public void deleteOnExit()
precondition
isFile is true
postcondition
At the time that the currently executing program terminates, the file identified by FileName will be deleted from the file system.
public boolean mkdir()
precondition
exists() is false
postcondition
An empty directory identified by FileName has been constructed
output
result == the directory creation was properly performed
public void setToReadOnly()
precondition
isFile() is true
postcondition
The file identified by FileName has permission that prohibit writing new values into the file.