Error: The file does not exist

advertisements

Now am working on a project where I need to create a folder in sdcard which am able to do. Also I need to hide/unhide it according to need. The code is working fine on emulator but not in device this is my code what went wrong ?

    public class FolderCreate extends MIDlet {
    private Form form;
    private Display display;
    FileConnection fc;
    String path;

        public void startApp() {        

        form = new Form("Hello World");
        String msg = "Hello World!!!!!!!";
        form.append(msg);
        display = Display.getDisplay(this);
        display.setCurrent(form);
     System.out.println("WWWW");
        try {
            path = System.getProperty("fileconn.dir.memorycard");
            System.out.println("Path : "+path+"/sample");
                fc = (FileConnection)Connector.open(path+"/ABCD/");
                if(!fc.exists())
                {
                   fc.mkdir();
                   System.out.println("directory created");
                }               

        } catch (IOException e) {
                // TODO Auto-generated catch block
                //System.out.println("ERROR "+e.getMessage());
            Alert alert = new Alert("Alert");
            alert.setString(e.getMessage());
            display.setCurrent(alert);
        }
        try
        {
            //fc = (FileConnection)Connector.open(path+"/sample/");
            if(fc.isHidden())
                {
                    fc.setHidden(false);
                }
            else{
                    fc.setHidden(true);
            }
         fc.close();
        }
        catch (Exception e)
        {
             Alert alert = new Alert("Alert2");
            alert.setString(e.toString());
            display.setCurrent(alert);
        }

    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
        System.out.println("Destroyed");
        notifyDestroyed();
    }
}

The error am getting is: java.io.IOException: file does not exist


Check if path starts with "file://". If not, add the suffix.

path = System.getProperty("fileconn.dir.memorycard");
if (path != null && !path.startsWith("file://")) {
    path = "file://" + path;
}