View RSS Feed

My Java Tips

Jsr 75

Rate this Entry
by , 11-22-2011 at 06:52 PM (1887 Views)
JSR 75 specifies 2 optional packages for mobile devices. I will be talking about these in the next few posts.

The two provided packages are:
Java Code:
PIM stands for personal information and it contains following information:
- contact list
- todo list
- events

If you want to access these from a J2ME application, then javax.microedition.pim is to be used.

Mobile devices have a file system which contains files. You might be interested in fetching those and playing with them. In that case, provides you with all the needed functionalities.


FileConnection // Interface for access to files or directories.
FileSystemListener // Listener interface for receiving status notification when adding or removing a file-system root.


FileSystemRegistry // Central registry for listeners that need to add or remove a file system.
ConnectionClosedException // Exception thrown when a method of a file connection is invoked but cannot be completed because the connection is closed.
IllegalModeException // Exception thrown when a method is invoked that requires a particular security mode, such as READ or WRITE, but the connection opened is not in that mode.

Let me present an example. I will create/open a file from the file system using FileConnection class of package.
Java Code:
public void createFile() {
   try {
      FileConnection filecon = (FileConnection)"file:///SDCard/mynewfile.txt");
      // Always check whether the file or directory exists.
      // Create the file if it doesn't exist.
      if(!filecon.exists()) {
   } catch(IOException ioe) {
As you know already, we use JSR 75 optional package ( to access the files on the mobile device.

After getting the FileConnection, we will use an inputstream to read the contents into a byte array. Once we have all the contents int he byte array, we will display the contents on the console after converting them into String.

Java Code:
public void showFile(String fileName) {
   try {
      FileConnection fc = (FileConnection)"file:///CFCard/" + fileName);
      if(!fc.exists()) {
         throw new IOException("File does not exist");
      InputStream is = fc.openInputStream();
      byte b[] = new byte[1024];
      int length =, 0, 1024);
         ("Content of "+fileName + ": "+ new String(b, 0, length));
   } catch (Exception e) {

Submit "Jsr 75" to Facebook Submit "Jsr 75" to Digg Submit "Jsr 75" to Submit "Jsr 75" to StumbleUpon Submit "Jsr 75" to Google

Tags: j2me, jsr 75, pim Add / Edit Tags
Java ME


  1. henna's Avatar
    • |
    • permalink
    i want to read a text file, where should i be saving it..