j2me fileconnection java.io.IOException: Root is not accessible

2.2k Views Asked by At
 FileConnection c = (FileConnection) Connector.open("file:///c:/myfile.txt",Connector.READ_WRITE);

        if (c.exists())
        {
            System.out.println("exist");

            }
        else {
                System.out.println("no exist");
                c.create();
        }

        OutputStream out = c.openOutputStream();
        PrintStream output = new PrintStream( out );
        output.println( response );
        out.close();
        c.close();

in the above code I m getting the following error:

   no exist
java.io.IOException: Root is not accessible
        at com.sun.midp.io.j2me.file.Protocol.ensureConnected(Protocol.java:1588)
        at com.sun.midp.io.j2me.file.Protocol.ensureOpenAndConnected(Protocol.java:1604)
        at com.sun.midp.io.j2me.file.Protocol.create(Protocol.java:945)
        at hello.Midlet.traverse(Midlet.java:83)
        at hello.Midlet.startApp(Midlet.java:40)
        at javax.microedition.midlet.MIDletProxy.startApp(MIDletProxy.java:43)
        at com.sun.midp.midlet.Scheduler.schedule(Scheduler.java:374)
        at com.sun.midp.main.Main.runLocalClass(Main.java:466)
        at com.sun.midp.main.Main.main(Main.java:120)

The file file:\\c:\myfile.txt exists. How do i go about now ?

1

There are 1 best solutions below

0
Sydwell On

Looks like you need to set the MIDLet Permissions.

Note you might get this working on the simulator but you will need signed code at least to get working on a real device.