Writing to a file - java.lang.IllegalArgumentException: Root is not specified

Posted on 2008-11-11
Last Modified: 2013-11-24
I am trying to write to a file on a J2ME emulator but I keep getting the error within the subject.  I have pasted my code.  Thanks

      FileConnection filecon = (FileConnection)"file:///myfile.txt");
      // Always check whether the file or directory exists.
      // Create the file if it doesn't exist.
      if(!filecon.exists()) {
         System.out.println("CREATING FILE");
         System.out.println("CREATED FILE");
   } catch(IOException ioe) {
   System.out.println("ERROR CREATING FILE");
Question by:vandy02
    1 Comment
    LVL 6

    Accepted Solution

    When you run the midlet, look at the output for the line "running with storage root ..."  Go to that directory in Explorer. You should see a folder called "filesystem" in that folder you should see a directory like "root1" If that is the case you should specify ""file:///root1/mynewfile.txt");
    I'm using NetBeans. Eclipse may differ slightly.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
    This video teaches viewers about errors in exception handling.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now