折腾了几天终于在moto E2手机上的文件访问成功了,我在j2me中访问手机目录
目录前缀file:// 也可以用 file://localhost
主目录/
手机目录 phone/
手机目录中的子目录有:
MyAudio/
MyDocument/
MyImages/
MyProgram/
MyVideo/
MyVoice/
可以自建目录
public static void creatzhuanji(String name)// 新建新专辑
{
try {
System.out.println("b11");
// footPath = file:///phone/
fc = (FileConnection) Connector.open(footPath + name + "/",Connector.READ_WRITE);
System.out.println("b2");
System.out.println(fc.exists());
if (!fc.exists())
fc.mkdir();// 创建文件jia
} catch (IOException ex) {
//ex.printStackTrace();
}
}
删除目录
public static void deletezhuanji(int id)
{//vector专辑目录下的一个子目录
String name =(String) vzhuanji.elementAt(id);
try {
System.out.println(footPath + name + "/");
if(name.equals("其它"))
{
System.out.println("不能删除");
}else{
fdir = (FileConnection) Connector.open(footPath + name + "/",
Connector.READ_WRITE);
if (fdir.exists())
{
System.out.println("deletestart");
Enumeration list = fdir.list();
if (list.hasMoreElements()) {
while (list.hasMoreElements()) {
String str = (String) list.nextElement();
System.out.println(footPath + name + "/"+str+" str:");
fc = (FileConnection) Connector.open(footPath + name + "/"+str,
Connector.READ_WRITE);
fc.delete();
}
}
fdir.delete();
System.out.println("deleteend");
}
}
} catch (IOException ex) {
//ex.printStackTrace();
}
}
//重命名
fc.rename(String filename) //可以是文件,也可以是目录
www.j2mehome.com