日期:2014-05-20  浏览次数:20710 次

求助! j2me如何遍历手机目录
j2me中用FileConnection如何遍历手机目录中的所有文件???   希望给出代码片段,谢谢

------解决方案--------------------
mark
------解决方案--------------------
FileSystemRegistry.listRoots()
FileConnection.list()

------解决方案--------------------
用楼上说的那几个接口,,遍历是可以实现的,,不难,,,不过有些手机是有存储卡的 可能要几个盘,要让用户选择
------解决方案--------------------
用到的接口,我都知道,关键是这个遍历的思路,我不是太清晰,希望大家指点,谢谢!
------解决方案--------------------
jsr75
------解决方案--------------------
楼主大哥 小弟想问问怎样读取手机目录 小弟是想读取手机铃声。
------解决方案--------------------
package example.fc;

import java.util.*;
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.io.file.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
* Demonstration MIDlet for File Connection API. This MIDlet implements simple
* file browser for the filesystem avaliable to the J2ME applications.
*
*/
public class FileBrowser extends MIDlet implements CommandListener {

private String currDirName;

private Command view = new Command( "View ", Command.ITEM, 1);

private Command write = new Command( "Write ", Command.ITEM, 2);

private Command creat = new Command( "New ", Command.ITEM, 2);

private Command creatOK = new Command( "OK ", Command.OK, 1);

private Command save = new Command( "save ", Command.OK, 1);

private Command prop = new Command( "Properties ", Command.ITEM, 2);

private Command back = new Command( "Back ", Command.BACK, 2);

private Command exit = new Command( "Exit ", Command.EXIT, 3);

private String writeFileName = " ";

private TextField nameInput; // Input field for new file name

private TextField content;

private ChoiceGroup typeInput; // Input fiels for file type (regular/dir)

private final static String[] attrList = { "Read ", "Write ", "Hidden " };

private final static String[] typeList = { "Regular File ", "Directory " };

private final static String[] monthList = { "Jan ", "Feb ", "Mar ", "Apr ",
"May ", "Jun ", "Jul ", "Aug ", "Sep ", "Oct ", "Nov ", "Dec " };

private Image dirIcon, fileIcon;

private Image[] iconList;

/* special string denotes upper directory */
private final static String UP_DIRECTORY = ".. ";

/*
* special string that denotes apper directory accessible by this browser.
* this virtual directory contains all roots.
*/
private final static String MEGA_ROOT = "/ ";

/* separator string as defined by FC specification */
private final static String SEP_STR = "/ ";

/* separator character as defined by FC specification */
private final static char SEP = '/ ';

public FileBrowser() {
currDirName = MEGA_ROOT;
try {
dirIcon = Image.createImage( "/icons/dir.png ");
} catch (IOException e) {
dirIcon = null;
}
try {
fileIcon = Image.createImage( "/icons/file.png ");