大家好,如何使用j2me midp2.0讀取手機中存儲的文本文件?
我在J2ME MIDP2.0應用environment.My工作要讀取存儲在移動device.How一個文本文件中讀取編程方式使用j2me.Please文本文件給我的想法得到這是什麼移動的根文件夾放置文本文件可以從j2me應用程序環境訪問。
Saravanan.P
大家好,如何使用j2me midp2.0讀取手機中存儲的文本文件?
我在J2ME MIDP2.0應用environment.My工作要讀取存儲在移動device.How一個文本文件中讀取編程方式使用j2me.Please文本文件給我的想法得到這是什麼移動的根文件夾放置文本文件可以從j2me應用程序環境訪問。
Saravanan.P
你需要javax.microedition.io.file.FileConnection
獲得root文件夾:
try {
Enumeration roots = FileSystemRegistry.listRoots();
while(roots.hasMoreElements()) {
System.out.println("Root: file:///"+(String)roots.nextElement());
}
} catch(Exception e) {
}
寫入文件
public void write(String root) {
FileConnection fc = null;
String fName = "test.txt";
try {
fc = (FileConnection) Connector.open(root + fName, Connector.READ_WRITE);
if(!fc.exists()) {
fc.create();
}
DataOutputStream dos = fc.openDataOutputStream();
dos.writeUTF("test-test");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
fc.close();
} catch (IOException e) { }
}
}
從文件中讀取
public void read(String root) {
FileConnection fc = null;
try {
fc= (FileConnection) Connector.open(root + "test.txt", Connector.READ);
DataInputStream dis = fc.openDataInputStream();
String data = dis.readUTF();
System.out.println(data);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
fc.close();
} catch (IOException e) { }
}
}
同相關主題的諾基亞論壇討論。供您參考看到這個link...這可能是幫助你... :)
更好u使用的FileConnection。
FileConnection fc=(FileConnection)Connector.ope(url);
嗨oxigen,在這裏,我提到的文本文件名?請指導我 – Saravanan 2010-12-21 10:37:05
小樣本加入 – oxigen 2010-12-21 12:38:45
謝謝,我會檢查它,讓你知道我的答案...非常感謝... – Saravanan 2010-12-21 12:58:33