0
A
回答
0
import java.io.IOException;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.Enumeration;
import java.util.Hashtable;
import javax.microedition.io.Connector;
import javax.microedition.io.file.*;
/**
* @author crazywizard
*/
public class RootMIDlet extends MIDlet implements CommandListener{
private List list;
private Command exitCommand;
private Hashtable allowed_types;
public RootMIDlet(){
/* Construct MIDlet */
//Define the file types of interest here
allowed_types = new Hashtable();
allowed_types.put("mp3", "audio/mp3");
}
public void startApp() {
list = new List("My Files", List.IMPLICIT);
exitCommand = new Command("Exit", Command.EXIT, 0);
list.addCommand(exitCommand);
list.setCommandListener(this);
Display.getDisplay(this).setCurrent(list);
getRootList();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void getRootList(){
//Get ALL available filesystem mounts
Enumeration drives = FileSystemRegistry.listRoots();
while(drives.hasMoreElements()){
//Iterate through the drives
String driveString = drives.nextElement().toString();
list.append("Searching "+driveString, null);
getFileList("file:///"+driveString);
}
}//--End of getRootList()
public void getFileList(String path){
try {
//Open path
FileConnection fc = (FileConnection)Connector.open(path, Connector.READ);
//Get list of ALL files and dirs
Enumeration filelist = fc.list(); //Get Hidden files as well --fc.list("*", true);
while(filelist.hasMoreElements()){
String filename = (String)filelist.nextElement();
FileConnection fc1 = (FileConnection)Connector.open(path+filename, Connector.READ);
//Check for dirs
if(fc1.isDirectory()){
//Apply recursion here
getFileList("file://"+fc1.getPath()+filename); //Note use of *double // instead of triple ///. Adjust accordingly according to phone platform
}else{
//Filter for only allowed types == .mp3
String file_type = getFileType(filename).toLowerCase();
if(!allowed_types.containsKey(file_type)){
//Do Nothing and Pass
continue;
}
list.append(fc1.getPath()+filename, null);
}
}
//Clean resources
fc.close();
} catch (IOException ioe) {
ioe.printStackTrace();
Display.getDisplay(this).setCurrent(new Alert("Error", ioe.toString(), null, AlertType.ERROR));
} catch (Exception ex) {
ex.printStackTrace();
Display.getDisplay(this).setCurrent(new Alert("Error", ex.toString(), null, AlertType.ERROR));
}
}
/* Helper Method */
private String getFileType(String fileName){
//Get file extension from fileName
char ch = '.';
int index = fileName.lastIndexOf((int)ch);
return fileName.substring(index+1);
}//--End of getFileType(String)
public void commandAction(Command c, Displayable d) {
if(c == exitCommand){
notifyDestroyed();
}
}
}
相關問題
- 1. 如何獲得一個Alexa技巧流媒體MP3到設備
- 2. 如何動態獲取/ res/raw中的所有媒體文件?
- 3. 如何修復諾基亞設備中的媒體異常(J2me)
- 4. 如何在j2me中使用cellid獲取lat和long的設備?
- 5. 如何停止流媒體MP3文件
- 6. 如何獲取計算機上的所有媒體文件
- 7. 如何在J2ME存儲卡中的文件中播放.mp3歌曲
- 8. 如何檢查J2ME設備中是否存在SIM卡?
- 9. 如何在支持J2ME的設備中獲取設備,製造商和型號?
- 10. iOS流媒體MP3文件
- 11. 如何在Android設備上查找和刪除設備上的媒體文件
- 12. 如何訪問SD卡中所有子文件夾中的所有mp3文件?
- 13. 獲取外部卡上的所有MP3文件
- 14. 如何在J2ME中捕獲MP3?
- 15. 如何獲得緩存在Firefox內存中的mp3文件?
- 16. 獲取Android 2.3中的所有非媒體文件
- 17. 如何獲得支持J2ME的所有設備的IMEI?
- 18. 廣告和媒體設備
- 19. 如何在UIWebview中停止流媒體MP3文件
- 20. 如何錄製和保存爲MP3在線流媒體音頻
- 21. 獲取所有媒體的所有喜歡和評論標籤
- 22. Javascript正則表達式來獲取來自Css的所有媒體查詢
- 23. 如何獲取媒體設置wordpress
- 24. 是否有API調用來獲取所有sata硬件設備?
- 25. 如何在所有Android設備上訪問和存儲SD卡中的數據?
- 26. 如何獲取sitecore中的所有媒體項目?
- 27. 如何在WordPress中重命名所有媒體文件?
- 28. iPhone:如何下載媒體文件並將其保存在設備上
- 29. Android:如何以MP3格式獲取媒體記錄器輸出?
- 30. 如何從網站獲取mp3音頻流媒體網址?