Question

I want to create my Application directory to save my configuration file. but blackberry simulator throws an exception on creating directory. i have tried the following code.

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();
}

Exception throw

net.rim.device.api.io.file.FileIOException: Not a directory
Was it helpful?

Solution

Have you tried adding a forward-slash to the end of your path so the connector knows it's a directory?

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();
}

OTHER TIPS

Are you sure the device/simulator you're testing on has internal storage? You should use FileSystemRegistry to get available file system roots, eg from the API docs:

   Enumeration rootEnum = FileSystemRegistry.listRoots();
   while (rootEnum.hasMoreElements()) {
      String root = (String) rootEnum.nextElement();
      FileConnection fc = (FileConnection) Connector.open("file:///" + root);
      System.out.println(fc.availableSize());
   } 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top