電話でも外部メモリでも、すべての画像を取得できるアプリケーションを作成したいと考えています。そのすべての画像をアプリケーションにインポートしたいと考えています。どうすればそれが可能になりますか?ファイル接続でできることを知りました。しかし、正確なアイデアが得られません。
2064 次
2 に答える
6
- を使用して、すべてのファイル システム ルートを取得します。
FileSystemRegistry.listRoots()
- を使用して、各ルートへの接続を順番に開きます
FileConnection fconn = (FileConnection)Connector.open(root)
- を使用してフォルダを一覧表示します
fconn.list()
。 - リスト内の各エントリについて、末尾が画像拡張子 (
file.getName().endsWith(".png")
など) の場合、それは画像です。 - エントリがフォルダの場合 (
file.isDirectory()
true を返す)、fconn.setFileConnection(folder)
そのディレクトリにトラバースするために使用します/ - すべてのルートのすべてのフォルダーに対して同じことを再帰的に行います。
于 2011-02-18T08:41:11.750 に答える
2
これは、私がかつてアプリケーションに使用したコード スニペットです。ファンキーブロスのステップでもほぼ同じです。
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();
}
于 2011-02-21T15:05:36.767 に答える