Java Reference
In-Depth Information
The possible root strings can be queried using the PushRegistry.listRoots() method. In order
to simplify path concatenation they have a trailing "/".
The following list shows examples of possible root strings:
CFCard/
SDCard/
MemoryStick/
C:/
usr/
sda1/
When compared with other GCF connections, the connection behavior of the file connection differs to
some extent. The Connector.open() method can successfully return a FileConnection object
although the referenced file or directory does not yet existent. This behavior is necessary for creating
files and directories. The following code snipped shows how the FileConnection interface can be
used to create a directory, given the device provides a "SDCard" file system root:
try {
FileConnection fileConn =
(FileConnection)Connector.open("file:///SDCard/MyDir/");
if (!fileConn.exists())
fconn.mkdir();
fconn.close();
}
catch (IOException ioe) {
// handle the error that occurred during directory creation
}
If a platform does not support file connections, it will throw a
javax.microedition.io.ConnectionNotFoundException when an application tries to
open a particular connection using Connector.open() method.
The FileConnection is derived from the StreamConnection interface and supports its
methods for opening input and output streams. Furthermore, the interface defines methods such as
create() and delete() for creating and deleting files, and methods to check the capability of
reading and writing of a file such as canRead() and canWrite() . Also methods to query
information about the memory space available and currently occupied are provided.
FileSystem Security
The security model supported for FileConnections is device and implementation dependent.
Accessing a file connection is restricted to prevent unauthorized access and manipulation of data.
Implementations must prohibit access to RMS databases, private data, and internal files of the
operating system. The security model may be applied already at the invocation of the
Connector.open() method. When the URL passed to the Connector.open() method points
to a file or directory that is not allowed to be accessed, a java.lang.SecurityException may
be thrown. The security model may also be applied later, when an application actually tries to open a
stream.
Registering FileSystemListeners Using the FileSystemRegistry
Since the functionality of the FileConnection is defined in an interface and not in an abstract class
that could hold static methods as well, the functionality to add and remove FileSystemListeners
is contained in a separate class. The FileRegistry class contains three static methods. The
addFileSystemListener() method is used to register a new FileSystemListener , and the
Search WWH ::




Custom Search