Using FileConnection API

The FC API provides the following classes and interfaces for accessing the device file system and performing file-related operations:

  • FileConnection

    Use the FileConnection interface to open a connection to a file or directory and to perform operations on that file or directory.

  • FileSystemListener

    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.

  • FileSystemRegistry

    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.

Checking device support for the FC API

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.

Checking the character used for separating directories

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.

Default directories

Series 40 and Nokia Asha software platform 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.

Virtual roots and directories

Nokia Asha software platform 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 Nokia Asha software platform devices, the corresponding virtual roots are Phone/ and Memory card/.

Likewise, Nokia Asha software platform devices support virtual directories such as Phone/_my_music/, which map to default storage directory for music in the phone’s memory drive. 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 Phone/_my_pictures/ directory but not necessarily to the C:/ root.