public class FileSystemRegistry extends Object
FileConnection
,
FileSystemListener
Modifier and Type | Method and Description |
---|---|
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 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.
|
public static boolean addFileSystemListener(FileSystemListener listener)
listener
- The new FileSystemListener to be registered in
order to handle adding/removing file system roots.SecurityException
- if application is not given permission
to read files.NullPointerException
- if listener is null
.FileSystemListener
,
FileConnection
public static boolean removeFileSystemListener(FileSystemListener listener)
listener
- The FileSystemListener to be removed.NullPointerException
- if listener is null
.FileSystemListener
,
FileConnection
public static Enumeration listRoots()
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 Value | Opening 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()); }
SecurityException
- if application is not given permission
to read files.FileConnection