×

Discussion Board

Page 1 of 4 1234 LastLast
Results 1 to 15 of 48
  1. #1
    Registered User
    Join Date
    Dec 2004
    Location
    quezon city philippines
    Posts
    25

    Question is there a File class equivalent in J2ME?

    Hi! I was wondering if there was an equivalent class in j2me to the File Class in java's standard edition? i need to know if i could somehow get the files stored in a particular folder and use those files i get in my midlet and forms. Can somebody help me? I've been going over the API and to this time I haven't found anything useful yet.

    any ideas? thanks.. ^_^

  2. #2
    Registered User
    Join Date
    Apr 2006
    Posts
    7

    Re: is there a File class equivalent in J2ME?

    hey dude im having the same delemma.. I was wondering if you found an answer.. ror maybe you can answer this question for me.. Im streaming a file over to my midlet its a .jar file but i don't know how to accept it.. im using outputstream and if i take it in as a string it shows all the weird letters so i know the midlet is getting it.. I just want it to save it as a file type?!?!

  3. #3
    Super Contributor
    Join Date
    Nov 2003
    Location
    Bangalore , India
    Posts
    4,430

    Re: is there a File class equivalent in J2ME?

    Hi booga2! Welcome to Nokia Discussion Boards!!

    You could try using JSR75 FileConnection Optional Package

    Hope this links are of some help!

    Introduction To The FileConnection API (With Example) v1.1
    http://www.forum.nokia.com/info/sw.n..._v1_1.zip.html

    Getting Started with the FileConnection APIs
    http://developers.sun.com/techtopics...ion/index.html

    An Overview of the File Connection Optional Package
    http://developers.sun.com/techtopics...ion/index.html

    The Generic Connection Framework
    http://developers.sun.com/techtopics...ork/index.html

    Regards
    Gopal

  4. #4
    Super Contributor
    Join Date
    Mar 2006
    Location
    Phoenix, AZ. USA
    Posts
    556

    Re: is there a File class equivalent in J2ME?

    booga2, be carefull trying to save a jar, as some device wont let you, security exception...

    you can save as jpg, beleieve it or not, then rename to jar after finished dowwnloading, to fake out security, I know this happpens for a fact on a few devices
    Jason Glass
    http://IChiBanComputers.Com

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    7

    Re: is there a File class equivalent in J2ME?

    Hey guys.. thanks for the links.. they kinda helped.. I think something is wrong though.. I call the

    private void getRoots() {
    Enumeration drives = FileSystemRegistry.listRoots();
    System.out.println("The valid roots found are: ");
    while(drives.hasMoreElements()) {
    String root = (String) drives.nextElement();
    System.out.println("\t"+root);
    }
    }

    and my RESULT is
    The valid roots found are:
    root1/

    Then I try and use
    public void createFile() {
    try {
    FileConnection filecon = (FileConnection)
    Connector.open("file://root1/readme/", Connector.READ_WRITE);
    // Always check whether the file or directory exists.
    // Create the file if it doesn't exist.
    if(!filecon.exists()) {
    filecon.mkdir();
    System.out.println("File Created");
    }
    else{System.out.println("File NOT created");}
    filecon.close();
    } catch(IOException ioe) {System.out.println(ioe);
    }
    }

    and result is
    java.io.IOException: Root is not accessible

    even if i interchange filecon.create();

    Any suggestions.. All i want to do is retrieve a stream from a server to my midlet and save a file in the midlet.. Who new it would be this hard! if any help it would be greatly appreciated..

  6. #6
    Super Contributor
    Join Date
    Mar 2006
    Location
    Phoenix, AZ. USA
    Posts
    556

    Re: is there a File class equivalent in J2ME?

    your url is referencing a FOLDER called readme, not a file called readme or readme.txt

    current:
    Connector.open("file://root1/readme/", Connector.READ_WRITE);

    change to:
    Connector.open("file://root1/readme", Connector.READ_WRITE);
    Jason Glass
    http://IChiBanComputers.Com

  7. #7
    Registered User
    Join Date
    Apr 2006
    Posts
    7

    Re: is there a File class equivalent in J2ME?

    Sorry A little typo.. here
    public void createFile() {
    try {
    FileConnection filecon = (FileConnection)
    Connector.open("file:////read.txt", Connector.READ_WRITE);
    // Always check whether the file or directory exists.
    // Create the file if it doesn't exist.
    if(!filecon.exists()) {
    filecon.create();
    System.out.println("File Created");
    }
    else{System.out.println("File NOT created");}
    filecon.close();
    } catch(IOException ioe) {System.out.println(ioe);
    }
    }


    java.io.IOException: Root is not accessible

  8. #8
    Registered User
    Join Date
    Dec 2005
    Location
    Brazil
    Posts
    1,884

    Re: is there a File class equivalent in J2ME?

    Hi bogaa2,

    Are you sure you're using four (not three) forward slashes in the URL or is it another typo?

    Besides, have you checked the Intro to FileConnection tutorial provided by Gopal?

    Introduction To The FileConnection API (With Example) v1.1
    http://www.forum.nokia.com/info/sw....I_v1_1.zip.html

    That tutorial states the following:

    Typical URL - file:///C:/Nokia/Images/Image(001).jpg

    "The roots of the file system are device-specific and they don’t necessarily correspond to physical memory units since they are logically defined by the device’s operating system. Furthermore, some Nokia devices support virtual roots that are basically links pointing to certain denoted directories. For instance, the location of captured images in a memory card could be located in the file:///e:/Nokia/Images path under the e: root, but additionally there is an Images/ virtual root which points to the actual physical location. This makes it easier to find such locations and also eases the security permissions, given that a MIDlet may have access rights to the Images/ root but not necessarily to the e:/ root. The FileSystemRegistry class provides the listRoots() utility method that returns an enumeration of the roots on the file system. This includes both logical and virtual roots."

  9. #9
    Super Contributor
    Join Date
    Mar 2006
    Location
    Phoenix, AZ. USA
    Posts
    556

    Re: is there a File class equivalent in J2ME?

    and juarez, isnt also true that many devices will not let java write specifically to the root? The java app, has certain directories it is allowed to write, read, iterate, and create delete from?

    This is what I am finding.
    Jason Glass
    http://IChiBanComputers.Com

  10. #10
    Registered User
    Join Date
    Apr 2006
    Posts
    7

    Re: is there a File class equivalent in J2ME?

    Yup that is copied right out of my code.. Sorry im fairly new at this J2ME Stuff.. Im writing this code using eclipse.. could that have to do with something being that its just an editor and there really isn't a space for it?

  11. #11
    Super Contributor
    Join Date
    Mar 2006
    Location
    Phoenix, AZ. USA
    Posts
    556

    Re: is there a File class equivalent in J2ME?

    i use netbeans with the ide, and when I exceute or run it, it uses wtk emulator, and i have no problems accessing the file system.

    can you run the wtk standalone? i.e. start->programs->wtk->Run MIDP application

    browse to where your jar and jad are located

    select jad, which will launch emulator

    now does your app read and write correctly?

    In netbeans, when you use the WTK as a simulator, then netbeans creates it's own copy of the WTK emulator folder

    so if i launch the standalone wtk and write a file
    it cannot be read from the netbeans wtk emulator and vice versa, they use different paths on my PC for the location of the emulators file system

    so take eclipse out of the picture, and see if it works in default WTK
    Jason Glass
    http://IChiBanComputers.Com

  12. #12
    Registered User
    Join Date
    Apr 2006
    Posts
    7

    Re: is there a File class equivalent in J2ME?

    WTK OTA server started ...

    Error: Reason = 36



    I get when i run it from programs>WTK>RUNAPI

  13. #13
    Super Contributor
    Join Date
    Mar 2006
    Location
    Phoenix, AZ. USA
    Posts
    556

    Re: is there a File class equivalent in J2ME?

    This is working fine for me, the file exists, so it is not created, instead, it is read, and system out'd with a little extra padding at end

    Code:
    public void createFile() 
    {
    try {
    FileConnection filecon = (FileConnection)
    Connector.open("file:///root1/readme", Connector.READ_WRITE);
    // Always check whether the file or directory exists.
    // Create the file if it doesn't exist.
    if(!filecon.exists()) {
    filecon.mkdir();
    System.out.println("File Created");
    }
    else
    {
        System.out.println("File NOT created, it exists");
        InputStream fis = filecon.openInputStream();
        byte[] b = new byte[1024];
        int length = fis.read(b, 0, 1024);
        fis.close();
        System.out.println("File Data:");
        System.out.println(new String(b));
    }
    filecon.close();
    } catch(Exception ioe) {System.out.println(ioe);
    }
    }
    Jason Glass
    http://IChiBanComputers.Com

  14. #14
    Super Contributor
    Join Date
    Mar 2006
    Location
    Phoenix, AZ. USA
    Posts
    556

    Re: is there a File class equivalent in J2ME?

    you dont want to run it in OTA mode, dont select "OTA provisioning", select "Run MIDP application"

    you should get a dialogue asking for location of your jad files
    Jason Glass
    http://IChiBanComputers.Com

  15. #15
    Registered User
    Join Date
    Apr 2006
    Posts
    7

    Re: is there a File class equivalent in J2ME?

    Hey Thanks .. Ya thats it .. it works running it through WTK.. Sorry the other error was because i didn't deploy the new code :S... I still can't write to root it still says my accessiblility is not allowed but i can create directories in the SDCard directories.. Thanks.. Man that sux i spent along time trying to research that to find out what the hell was wrong Thanks for your help Your Legend!

Page 1 of 4 1234 LastLast

Posting Permissions

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