2012-06-23 121 views
3

我想创建我的应用程序目录来保存我的配置文件。但黑莓模拟器在创建目录时会引发异常。我已经尝试了下面的代码。在黑莓应用程序的创建目录中抛出“FileIOException:不是目录”

try { 
FileConnection myAppDir = (FileConnection) Connector.open("file:///store/home/user/myAppDir", Connector.READ_WRITE); 
    if (!myAppDir.exists()){ 
     myAppDir.mkdir(); // Exception throw here 
    } 
} catch (Exception e) { 
e.printStackTrace(); 
} 

异常抛出

net.rim.device.api.io.file.FileIOException: Not a directory 

回答

5

您是否尝试过加入正斜到路径的末尾,以便在连接器知道这是一个目录?

try { 
FileConnection myAppDir = (FileConnection) Connector.open("file:///store/home/user/myAppDir/", Connector.READ_WRITE); 
    if (!myAppDir.exists()){ 
     myAppDir.mkdir(); // Exception throw here 
    } 
} catch (Exception e) { 
e.printStackTrace(); 
} 
2

您确定您正在测试的设备/模拟器是否具有内部存储?您应该使用FileSystemRegistry来获取可用的文件系统根,例如从API文档:

Enumeration rootEnum = FileSystemRegistry.listRoots(); 
    while (rootEnum.hasMoreElements()) { 
     String root = (String) rootEnum.nextElement(); 
     FileConnection fc = (FileConnection) Connector.open("file:///" + root); 
     System.out.println(fc.availableSize()); 
    } 
相关问题