我想把应用程序放在哪里可以获得所有图像,无论是在手机还是在外部存储器中。我想在我的应用程序中导入所有图像。怎么可能?我开始知道通过文件连接是可能的。但没有得到确切的想法。
答案 0 :(得分:6)
FileSystemRegistry.listRoots()
FileConnection fconn = (FileConnection)Connector.open(root)
fconn.list()
列出文件夹。file.getName().endsWith(".png")
等)结束,那么它就是图像。file.isDirectory()
返回true),则使用fconn.setFileConnection(folder)
遍历该目录/ 答案 1 :(得分:2)
这是我曾经用于我的应用程序的代码片段。它或多或少在funkybros步骤中也是如此。
protected void showFiles() {
if (path == null) {
Enumeration e = FileSystemRegistry.listRoots();
path = DATAHEAD; //DATAHEAD = file:///
setTitle(path);
while (e.hasMoreElements()) {
String root = (String) e.nextElement();
append(root, null);
}
myForm.getDisplay().setCurrent(this);
} else {
//this if-else just sets the title of the Listing Form
if (selectedItem != null) {
setTitle(path + selectedItem);
}
else {
setTitle(path);
}
try {
// works when users opens a directory, creates a connection to that directory
if (selectedItem != null) {
fileConncetion = (FileConnection) Connector.open(path + selectedItem, Connector.READ);
} else // works when presses 'Back' to go one level above/up
{
fileConncetion = (FileConnection) Connector.open(path, Connector.READ);
}
// Check if the selected item is a directory
if (fileConncetion.isDirectory()) {
if (selectedItem != null) {
path = path + selectedItem;
selectedItem = null;
}
//gathers the directory elements
Enumeration files = fileConncetion.list();
while (files.hasMoreElements()) {
String file = (String) files.nextElement();
append(file, null);
}
//
myForm.getDisplay().setCurrent(this);
try {
if (fileConncetion != null) {
fileConncetion.close();
fileConncetion = null;
}
} catch (IOException ex) {
ex.printStackTrace();
}
}//if (fileConncetion.isDirectory())
else {
System.out.println(path);
//if it gets a file then calls the publishToServer() method
myForm.publishToServer();
}