Search code examples
blackberryfile-iocreate-directory

Throw "FileIOException:Not a directory" on create directory in blackberry application


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

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