Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

Using files in J2ME

Thread view: 
joseph.paterson@gmail.com - 01 May 2006 08:26 GMT
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:
try
{
    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
nothing.
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 ?

Cheers,

- Joseph Paterson
David N. Welton - 01 May 2006 11:27 GMT
> Hi everyone,
>
> I'm trying to open and read from a file using J2ME, but I seem to have
> a problem.

> 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
> nothing.

> 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 ?

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

http://svn.sourceforge.net/viewcvs.cgi/hecl/trunk/hecl/j2me/Hecl.java?view=markup

Specifically, have a look at the code around

   DataInputStream is = new DataInputStream(
        this.getClass().getResourceAsStream("/script.hcl"));

Ciao,
Signature

David N. Welton
- http://www.dedasys.com/davidw/

Linux, Open Source Consulting
- http://www.dedasys.com/

Darryl L. Pierce - 01 May 2006 11:28 GMT
> Hi everyone,
>
[quoted text clipped - 5 lines]
>     input = Connector.openDataInputStream ("words");
> } catch (Exception e) { this.notifyDestroyed (); }

If you want to open a file *from your JAR* you need to use
MIDlet.getResourceAsStream(String) and need to prepend "/" to it.

> I also tried using file://words, but I get an error.

That's because file:// is a protocol that's not supported on the handset
you're using.

> 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
> nothing.

No, you can't find that out.

> 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 ?

It makes no difference, really, as far as efficiency is concerned.

Signature

Darryl L. Pierce <mcpierce@gmail.com>
Visit my homepage: <http://mcpierce.multiply.com>
"By doubting we come to inquiry, through inquiry truth." - Peter Abelard



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.