Wednesday, 16 April 2008

File access from Java Micro Edition

This article describes how to access files on a mobile device from a Java Micro Edition application. In particular how to access files that are at a random location on the device such as in the 'My Documents' folder on a Windows Mobile device.

The first hurdle you need to take is to determine whether the Runtime Environment will allow you to access files. Generally this will require that the Java Micro Edition Runtimes implements JSR-75. If you have a smartphone with a pre-installed Java Runtime you can look up the specs on the manufacturer's site, but don't raise your hopes. If you are using IBM J9 you are in luck, JSR-75 is supported.

To enable JSR-75 for IBM-J9 you need to (taken from Markus Brosch's blog):
  1. Get this jar file It contains a folder fixed with Personal Profile and MIDP subfolders and under that a directory structure analogous to the directory structure of the J9 runtime.
  2. Copy: fixed\ive-2.2\runtimes\wm2003\arm\midp2\bin\fileconn.dll into this folder on you mobile device: YourJ9Folder\bin\
    Copy: fixed\ive-2.2\runtimes\wm2003\arm\midp2\lib\jclMidp20\ext\fc.jar into this folder on you mobile device: YourJ9Folder\lib\jclMidp20\ext\
  3. If your Java Runtime was running, restart it.
You can then access files using the package.


Anonymous said...

Hi Robin
I followed your advice and installed JSR-75 on my pda, however im get the following error when i run my midlet
"Cannot parse scheme: /My Documents/Message.txt"
Just wondering if you've ever come across this error before?

Robin said...

It sounds like it's to do with the protocol (http:// or file://). Have you tried looking at the JSR-75 demo in the Sun wireless toolkit?
It was a while ago i tried this, but i remember it took me some time to get the protocol and path right for accessing the files i wanted.
If i were you i'd make a form where you can enter file url so you can test easily.

Anonymous said...

Hi Robin,
Thank you so much for your help, Sounds silly but ive been stuck on trying to access files for ages but i have finally gotten it working thanks to you posts :)