FileConnection Optional Package 1.0
Final Release

javax.microedition.io.file
Class FileSystemRegistry

java.lang.Object
  |
  +--javax.microedition.io.file.FileSystemRegistry

public class FileSystemRegistry
extends java.lang.Object

The FileSystemRegistry is a central registry for file system listeners interested in the adding and removing (or mounting and unmounting) of file systems on a device.

Since:
FileConnection 1.0
See Also:
FileConnection, FileSystemListener

Method Summary
static boolean addFileSystemListener(FileSystemListener listener)
          This method is used to register a FileSystemListener that is notified in case of adding and removing a new file system root.
static java.util.Enumeration listRoots()
          This method returns the currently mounted root file systems on a device as String objects in an Enumeration.
static boolean removeFileSystemListener(FileSystemListener listener)
          This method is used to remove a registered FileSystemListener.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addFileSystemListener

public static boolean addFileSystemListener(FileSystemListener listener)
This method is used to register a FileSystemListener that is notified in case of adding and removing a new file system root. Multiple file system listeners can be added. If file systems are not supported on a device, false is returned from the method (this check is performed prior to security checks).

Parameters:
listener - The new FileSystemListener to be registered in order to handle adding/removing file system roots.
Returns:
boolean indicating if file system listener was successfully added or not
Throws:
java.lang.SecurityException - if application is not given permission to read files.
java.lang.NullPointerException - if listener is null.
See Also:
FileSystemListener, FileConnection

removeFileSystemListener

public static boolean removeFileSystemListener(FileSystemListener listener)
This method is used to remove a registered FileSystemListener. If file systems are not supported on a device, false is returned from the method.

Parameters:
listener - The FileSystemListener to be removed.
Returns:
boolean indicating if file system listener was successfully removed or not
Throws:
java.lang.NullPointerException - if listener is null.
See Also:
FileSystemListener, FileConnection

listRoots

public static java.util.Enumeration listRoots()
This method returns the currently mounted root file systems on a device as String objects in an Enumeration. If there are no roots available on the device, a zero length Enumeration is returned. If file systems are not supported on a device, a zero length Enumeration is also returned (this check is performed prior to security checks).

The first directory in the file URI is referred to as the root, which corresponds to a logical mount point for a particular storage unit or memory. Root strings are defined by the platform or implementation and can be a string of zero or more characters ("" can be a valid root string on some systems) followed by a trailing "/" to denote that the root is a directory. Each root string is guaranteed to uniquely refer to a root. Root names are device specific and are not required to adhere to any standard. Examples of possible root strings and how to open them include:
Possible Root ValueOpening the Root
CFCard/ Connector.open("file:///CFCard/");
SDCard/ Connector.open("file:///SDCard/");
MemoryStick/ Connector.open("file:///MemoryStick/");
C:/ Connector.open("file:///C:/");
/ Connector.open("file:////");

The following is a sample showing the use of listRoots to retrieve the available size of all roots on a device:

   Enumeration rootEnum = FileSystemRegistry.listRoots();
   while (e.hasMoreElements()) {
      String root = (String) e.nextElement();
      FileConnection fc = Connector.open("file:///" + root);
      System.out.println(fc.availableSize());
   } 
 

Returns:
an Eumeration of mounted file systems as String objects.
Throws:
java.lang.SecurityException - if application is not given permission to read files.
See Also:
FileConnection

Final Release
Rev. 1.00

Copyright © 2002-2004 PalmSource, Inc. All Rights Reserved.
Java is a trademark of Sun Microsystems, Inc.