Using files in J2ME

Discussion in 'Java' started by joseph.paterson, May 1, 2006.

  1. Hi everyone,

    I'm trying to open and read from a file using J2ME, but I seem to have
    a problem.
    Essentially, I do this:
    input = Connector.openDataInputStream ("words");
    } catch (Exception e) { this.notifyDestroyed (); }

    I also tried using file://words, but I get an error. Is there a way for
    figuring what directory the Class is being executed in (so I could use
    file://${{PATH}words)? I looked into System.getProperty (), but found
    I also thought of putting the contents of the 'words' file directly
    into my .java code, but as the file is around 600kb (it's a
    dictionary...) I get a code too large error.

    Also, once I do actually figure out how to open and read from this
    file, should I read Byte's from the file or Char's ?


    - Joseph Paterson
    joseph.paterson, May 1, 2006
    1. Advertisements

  2. Hecl needs to do something similar, and we use a .jar "resource"

    Specifically, have a look at the code around

    DataInputStream is = new DataInputStream(

    David N. Welton

    Linux, Open Source Consulting
    David N. Welton, May 1, 2006
    1. Advertisements

  3. If you want to open a file *from your JAR* you need to use
    MIDlet.getResourceAsStream(String) and need to prepend "/" to it.
    That's because file:// is a protocol that's not supported on the handset
    you're using.
    No, you can't find that out.
    It makes no difference, really, as far as efficiency is concerned.
    Darryl L. Pierce, May 1, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.