Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

How to Access file stored along with midlet programs

Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I'm facing some problems accessing files(text files) packaged along with midlet programs .

I have an application which consists of a midlet and a configuration file(text file). The configuration file is also bundled along with the midlet and deployed onto the mobile phone. Now I need to access the file and read its contents how do i do it. I tried it using FileConnection API and other methods, but in vain could not succeed. Given below is sample code form my application which i have written to access the file.

String url="file:///myfile.cfg"
InputConnection con = (InputConnection)

When i try runnignthe application it gives "Malformed url" Exception.

I request one and all to kindly suggest me how do I solve this problem. It is required very urgently.

Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Well, first if you got only 1 text file and it isn't too big, you can add the properties to the .jad file (assuming it is in the same format).

Then you can acess those properties easily using:
getAppProperty(String key) in your Midlet.

If you can't do that then you can use the getClass().getResourceAsStream() method:

Then use the regular streams methods to read the contens into a buffer and then to string...
[ January 22, 2006: Message edited by: Roy Ben Ami ]
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic