Share on Google+Share on Google+

J2ME RMS Read Write

This Application specially tries to explain how to read and write the data using RecordStore class.

J2ME RMS Read Write


This Application specially tries to explain how to read and write the data using RecordStore class. In the RecordStore class the following methods are available:

  • addRecord(byte[] data, int offset, int numBytes) 
  • addRecordListener(RecordListener listener)
  • closeRecordStore()
  • deleteRecord(int recordId)
  • deleteRecordStore(String recordStoreName)
  • enumerateRecords(RecordFilter filter, RecordComparator comparator, boolean keepUpdated) 
  • getLastModified()
  • getName()
  • getNextRecordID()
  • getNumRecords()
  • getRecord(int recordId)
  • getRecord(int recordId, byte[] buffer, int offset)
  • getRecordSize(int recordId)
  • getSize()
  • getSizeAvailable()
  • getVersion()
  • listRecordStores()
  • openRecordStore(String recordStoreName, boolean createIfNecessary)
  • removeRecordListener(RecordListener listener)
  • setRecord(int recordId, byte[] newData, int offset, int numBytes)

The Application is as follows:


import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;

public class ReadWriteRMS extends MIDlet{
  private RecordStore rs = null;
  static final String REC_STORE = "ReadWriteRMS";

  public void startApp(){
  writeRecord("Core J2ME Technology");
  writeRecord("J2ME Wireless Toolkit");  

  public void pauseApp(){}

  public void destroyApp(boolean unconditional){

  public void openRecStore(){
  rs = RecordStore.openRecordStore(REC_STORE, true );
  }catch (Exception e){}

  public void closeRecStore(){
  }catch (Exception e){}

  public void deleteRecStore(){
  if (RecordStore.listRecordStores() != null){
  }catch (Exception e){}

  public void writeRecord(String str){
  byte[] rec = str.getBytes();
  rs.addRecord(rec, 0, rec.length);
  }catch (Exception e){}

  public void readRecords(){
  byte[] recData = new byte[5]
  int len;
  for(int i = 1; i <= rs.getNumRecords(); i++){
  if(rs.getRecordSize(i> recData.length){
  recData = new byte[rs.getRecordSize(i)];
  len = rs.getRecord(i, recData, 0);
  System.out.println("Record " + i + " : " +
new String(recData, 0, len));
  }catch (Exception e){}


Download Source Code



Posted on: December 2, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: J2ME RMS Read Write   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
Nsubuga Nicholas
April 17, 2011

how can i write data to the record store form the j2me form and retrieve it
January 10, 2012
source code j2me

does the rms create a record (exp: in a .txt file)? If so, where does this record resides?