Java Reference
In-Depth Information
public void delete() throws IOException
You should immediately call
close()
on the
FileConnection
after a
delete()
. The
FileConnection
is no longer valid once the underlying file has been deleted.
Similarly, to rename a file or directory, open it with
Connector.WRITE
mode enabled, and
then call the
rename()
method of the
FileConnection
instance with the new name:
public void rename(String newName) throws IOException
Listing Directory Content
When you have a
FileConnection
to a directory, you can obtain an
Enumeration
of its content
(files and subdirectory) using this method:
Enumeration list() throws IOException
Enumeration list(String filter, boolean includeHidden) throws IOException
The returned
Enumeration
contains objects of string type. Each object in the enumeration is the
name of a file or directory. If the object is a directory, the name will end with /.
The second form of
list()
uses a filter that can contain the * (asterisk) wildcard character.
For example, a filter value of “*.png” will select only the PNG graphics files in the directory. The
includeHidden
flag indicates whether the matching should be performed against files with the
hidden flag set.
To make directory traversal more efficient,
FileConnection
does not force you to go back
to GCF and use
Connector.open()
on every level of a new directory (although you can do so if
you want to). Instead, a convenient method allows you to dive down a specific subdirectory
(or move up) with the current
FileConnection
:
public void setFileConnection(String itemName) throws IOException
This will reset the
FileConnection
to the specified subdirectory, parent directory, or file.
The
itemName
must be a string that is from a
list()
-returned
Enumeration
.
Path and URL Information
Note that the string from a
list()
-returned
Enumeration
does not contain full path information,
or any of the “file:///” URL preamble. If you are only navigating subdirectories, you don't need
the full URL. However, if you actually need the full URL, you can call this method to get the
complete path and preamble:
public String getPath()
By appending the string from the
list()
-returned
Enumeration
to the string returned from
the preceding method, you end up with a full URL. The full URL is useful if you ever need to
open the file or directory again using the GCF
Connector.open()
.
If you already have a
FileConnection
open, you can always get the complete URL associated
it by calling the following method:
public String getURL()
Search WWH ::
Custom Search