• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Open a Text File with J2ME .

 
Murat Kaplan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to know about micro edition that if can i open a local file on a mobile phone. i mean i have a text file has 3 or 4 mb . i want to open and read line by line from that file. is this possible with j2me ?
 
dan moore
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i believe the midlet can only access data within its own jar or within its own area of flash (accessed through the microedition RMS apis).

as such, your text file can only get into RMS via the app - so it needs either to be downloaded or read from the jar.

so you're fairly stuffed: most devices won't let you have jars bigger than a few hundred kbytes at most, and a java app can't directly access an external file.

one possibility, on phones which allow native applications such as symbian, would be to run a little native http server which serves up the text file, then connect from the java app to http://localhost, but perhaps not what you're after.

there are some newer phones coming out in near future with filestore access i believe, some newfangled JSRs or other, don't see what's wrong with MIDP1 myself...

hth, dan.
 
Dave Butler
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Nope - you can't write a text file, but there are work-arounds:

1. Use resource bundles (read-only at runtime)
2. Use custom attributes in the JAD/JAR (RO at runtime)
3. Use a network connection and cache into an RMS (RW at runtime)

All 3 work, other there are some gotchas:

1. The MIDP 1 spec defines the RMS size as 8 KB (yup 8 KB), although the phone manufacturers usually give you a little more to work with - typically Nokia is 20 KB. The MIDP2 spec ups the minimum to 30 KB, but again manufacturers generally provide more.
2. Bear in mind resource files get packaged into the JAR - and there is a limit on JAR size. Best advice for MIDP 1 is around 50 KB, but some phones are less, some a more. "3" phones are a particalur pain.
3. We have also found a combined JAR + RMS size limit. Can't remember what it was because we work with a 35 KB JAR/20KB RMS limit.
4. Use an obfuscator.
5. Haven't found any particular problems with using custom attributes, but we haven't tried to max out JADs so don't know the edge of the size envelope.

Best Regards

Dave
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic