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

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)
      // 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");
Who is Participating?
CodeFishConnect With a Mentor Commented:
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 "Connector.open("file:///root1/mynewfile.txt");
I'm using NetBeans. Eclipse may differ slightly.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.