Java Reference
In-Depth Information
Display 10.12
Some Methods in the Class File (part 2 of 3)
public boolean canRead()
Tests whether the program can read from the file. Returns true if the file named by the abstract
path name exists and is readable by the program; otherwise returns false .
public boolean setReadOnly()
Sets the file represented by the abstract path name to be read only. Returns true if successful;
otherwise returns false .
public boolean canWrite()
Tests whether the program can write to the file. Returns true if the file named by the abstract path
name exists and is writable by the program; otherwise returns false .
public boolean delete()
Tries to delete the file or directory named by the abstract path name. A directory must be empty
to be removed. Returns true if it was able to delete the file or directory. Returns false if it was
unable to delete the file or directory.
public boolean createNewFile() throws IOException
Creates a new empty file named by the abstract path name, provided that a file of that name does
not already exist. Returns true if successful, and returns false otherwise.
public String getName()
Returns the last name in the abstract path name (that is, the simple file name). Returns the empty
string if the abstract path name is the empty string.
public String getPath()
Returns the abstract path name as a String value.
public boolean renameTo(File New_Name )
Renames the file represented by the abstract path name to New_Name . Returns true if successful;
otherwise returns false . New_Name can be a relative or absolute path name. This may require
moving the file. Whether or not the file can be moved is system dependent.
public boolean isFile()
Returns true if a file exists that is named by the abstract path name and the file is a normal file;
otherwise returns false . The meaning of normal is system dependent. Any file created by a Java
program is guaranteed to be normal.
public boolean isDirectory()
Returns true if a directory (folder) exists that is named by the abstract path name; otherwise
returns false .
public boolean mkdir()
Makes a directory named by the abstract path name. Will not create parent directories. See mkdirs ,
which follows. Returns true if successful; otherwise returns false .
 
Search WWH ::




Custom Search