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.