×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Regular Contributor
    Join Date
    Feb 2010
    Posts
    75

    java.io.IOException: Root is not accessible

    I am tring to open create a file in this path file://C:/Documents and Settings/My Documents/NetBeansProjects

    fileConnection = (FileConnection)Connector.open(url_FILE,Connector.READ_WRITE);

    fileConnection.create();

    but in the above code (fileConnection.create(); ) in this line it is showing
    the exception:

    java.io.IOException: Root is not accessible

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: java.io.IOException: Root is not accessible

    First, note that "file:" is usually followed by three "/".

    Second: there are many restrictions on reading and writing files in the device's file system. It is better to use the provided system properties for locating folders, rather than coding a path. For example, see the Forum Nokia wiki.

    Graham.

  3. #3
    Registered User
    Join Date
    Dec 2013
    Posts
    2

    Re: java.io.IOException: Root is not accessible

    Hello, I'm new to J2ME and working on Nokia Asha SDK 1.0, I tried the following code in order to create a file on the emulator:

    Code:
    Code:
    public void createFile() {
       try {
          FileConnection filecon = (FileConnection)
             Connector.open("file:///root1/myfile.txt");
          // Always check whether the file or directory exists.
          // Create the file if it doesn't exist.
          if (!filecon.exists()) {
             filecon.create();
          }
          filecon.close();
       } catch(IOException ioe) {
       }
    }
    but it gives me the error "java.lang.SecurityException: Root cannot be accessible", I also tried "file:///SDCard/myfile.xml" but the same error appears, I did a research on the forums and found this thread but I didn't find a proper solution for this, sorry if this problem was already adressed elsewhere and if that's the case, a link to the thread where this problem was solved will be appreciated.

    Thank you

  4. #4
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    682

    Re: java.io.IOException: Root is not accessible

    You should never count on the root name being hardcode in your app code,
    to obtain the list of roots available on the phone use
    FileSystemRegistry.listRoots();
    (note that some roots maybe read only and some writeable, you should check that via code)
    Heard of DVLUP? Join here

  5. #5
    Registered User
    Join Date
    Dec 2013
    Posts
    2

    Re: java.io.IOException: Root is not accessible

    Thank you shai.i for your help, I managed to found the root list and create a file on one of the root available, now I'll follow your advice and try to write a code to check if a root can be writable.

  6. #6
    Registered User
    Join Date
    Nov 2013
    Posts
    11

    Re: java.io.IOException: Root is not accessible

    Hey Tithi,

    Here is a quick example that works for me (Example accessing memory card), this method is a very safe way of accessing a root/directory, in-case your roots change in the future (Shai also mentioned this below):

    String folder = System.getProperty("fileconn.dir.memorycard");

    //read write permission

    FileConnection c = (FileConnection) Connector.open(folder, Connector.READ_WRITE);

    try {

    // Checking if the directoy exists or not.
    if (c.exists()) {
    System.out.println("location exists");
    }

    finally{
    c.close();
    }
    Hope this helps.

Similar Threads

  1. [moved] CA root certificate recognition within Nokia and Symbian applications
    By atilla.biler in forum Symbian Signed Support, Application Packaging and Distribution and Security
    Replies: 1
    Last Post: 2010-02-22, 07:41
  2. Missing Verisign ca on the N6131 Root Certification List
    By sure0812 in forum Mobile Java Networking & Messaging & Security
    Replies: 4
    Last Post: 2008-09-08, 19:50
  3. Replies: 0
    Last Post: 2008-04-15, 08:38
  4. java.io.IOException: Root is not accessible
    By pvumesh in forum Mobile Java General
    Replies: 1
    Last Post: 2007-04-16, 23:36
  5. java.io.IOException in emulator
    By remonvv in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 2004-08-03, 13:59

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×