Namespaces
Variants
Actions

How to list root file systems in Java ME

Jump to: navigation, search
SignpostIcon FloppyDisk 52.png
Article Metadata

Article
Created: jarmlaht (15 Feb 2008)
Last edited: hamishwillee (18 Jul 2012)

Overview

This article shows how to list currently mounted root file systems on a device. FileConnection API (JSR-75) has FileSystemRegistry.listRoots() method for this purpose.


The full source code for a test MIDlet:

Source code: RootMIDlet.java

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.Enumeration;
import javax.microedition.io.file.*;
 
public class RootMIDlet extends MIDlet implements CommandListener {
private Form form;
private Command exitCommand;
 
public void startApp() {
form = new Form("Root list");
exitCommand = new Command("Exit", Command.EXIT, 1);
form.addCommand(exitCommand);
form.setCommandListener(this);
Display.getDisplay(this).setCurrent(form);
createRootList();
}
 
public void pauseApp() {
}
 
public void destroyApp(boolean unconditional) {
}
 
protected void createRootList() {
form.append("Roots:\n");
Enumeration drives = FileSystemRegistry.listRoots();
while (drives.hasMoreElements()) {
String driveString = drives.nextElement().toString();
form.append(driveString + "\n");
}
}
 
public void commandAction(Command c, Displayable d) {
if (c == exitCommand) this.notifyDestroyed();
}
}

See also

This page was last modified on 18 July 2012, at 06:51.
179 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved