The FC API provides the following classes and interfaces for accessing the device file system and performing file-related operations:
Use the FileConnection
interface to open a connection to a file
or directory and to perform operations on that file or directory.
Use the FileSystemListener
interface to receive notifications when
a file system root is added to or removed from the device. A file
system root corresponds to the logical mount point for a particular
storage unit or memory (essentially a drive). For example, when the
user inserts a memory card into the device, a new root is added to
the device file system for that memory card.
The roots of a file system are device-specific and do not necessarily correspond to physical memory units since they are logically defined by the device's operating system. In addition, some devices support virtual roots.
If you use FileConnection
objects in a MIDlet, it is recommended that you also implement a FileSystemListener
to ensure that the MIDlet can react to
root changes in the device file system.
Use the FileSystemRegistry
class to add and remove FileSystemListeners
and to retrieve an enumeration of the roots available in the device
file system. The FileSystemRegistry
returns both
logical and virtual roots.
For more information about using the FC API, see:
For instructions on how to create a full example MIDlet that uses the FC API, see section Example: Accessing files on the device.
To check whether the device
supports the FC API, call the microedition.io.file.FileConnection.version
system property:
boolean isSupported = System.getProperty("microedition.io.file.FileConnection.version") != null;
If the FC API is supported, the system property returns the API
version number. If the FC API is not supported, the system property
returns null
.
To determine
the character used for separating directories in strings that represent
file and directory paths as shown to the user, call the file.separator
system property:
string separator = System.getProperty("file.separator");
The system property returns a string representing the separator character used by the device.
Note: Do not use the file.separator
value to construct URIs, since this can result in invalid URIs.
Series 40 and Symbian devices use a number of predefined directories as default locations for storing different types of data. For example, music clips, ring tones, and video clips are all stored in specific directories by default. You can use the FC API system properties to retrieve the localized names and file system URLs for these directories.
Not all devices support the same set of default directories and
thereby the same set of system properties, so make sure to check for null
values when using the system properties to construct
URLs.
Tip: To make your MIDlet look consistent with the device UI, use the localized names retrieved with system properties when displaying default directory names in the MIDlet UI. Do not use generic non-localized names.
For more information about constructing URLs, see section Accessing files and directories.
Some devices support virtual file
system roots, which act as links to predefined logical mount points.
For example, c:/
and e:/
are the
logical mount points (roots) for the main system drive and the memory
card slot. On some devices, the corresponding virtual roots are Internal/
and Memory card/
.
Likewise,
some devices support virtual directories, which map to default storage
directories such as C:/Data/Images/
and C:/Data/Music/
. These same directories are also defined in the FC API system properties. Virtual directories make it easier to find standard locations in
the device file system, and they also make it easier to deal with
security permissions, since a MIDlet may have access rights to the Internal/Images/
directory but not necessarily to the C:/
root.
For more information about virtual roots and directories, see section Virtual file system in Symbian.