Java Reference
In-Depth Information
File or Directory
An open
FileConnection
can be referring to either a directory or a file. You can determine if the
connection is associated with a directory via the following method:
public boolean isDirectory()
Some file systems, such as Win32, support hidden files. Hidden files do not appear on
regular directory listings, and are often used for system files. You can determine whether a file
or directory is hidden by calling the following method:
public isHidden()
On a file system that does not support hidden files,
isHidden()
always returns false. You
can also control the hidden attribute of a file on file systems that support it, by using this method:
public void setHidden(boolean hiddenFlag)
Setting
hiddenFlag
to true will make the file hidden, while a false value will make it visible.
This method has no effect on file systems that do not support hidden files nor on file systems
where you must rename the file to make files hidden.
Modifying File Attributes
Some file attributes may prevent you from reading or writing to a file. You can determine
whether a file can be read by using this method:
public boolean canRead()
Or find out if a file can be written to using the following:
public boolean canWrite()
To change the read or write attribute of a file on a file system that supports it, use this:
public void setReadable(boolean readable)
throws IOException
public void setWriteable(boolean readable) throws IOException
Note
Most of the input/output methods on the
FileConnection
interface will throw
ConnectionClosedException
if the call is made on a closed connection,
IllegalModeException
if a
write is tried on a connection that is opened as read-only, and
SecurityException
if the operation would
violate security policy. When a
SecurityException
is thrown, the operation is not actually performed. For
methods that accept arguments,
NullPointerException
and
IllegalArgumentException
may also
be thrown if an error occurs during argument processing.
■
Search WWH ::
Custom Search