Listing 3: Skeleton code for the RMS store management in the MIDlets FetchPage and History

// In FetchPage.java

// In the constructor:
URLStore = RecordStore.openRecordStore("CUJTestStore", true);
// Everytime an url is visited:
URLStore.addRecord(url.getBytes(), 0, url.length());
// In destroyApp():
URLStore.closeRecordStore();

// In History.java

// In the constructor:
URLStore = RecordStore.openRecordStore("CUJTestStore", true);
// Get all urls and append them to history:
RecordEnumeration re = URLStore.enumerateRecords(null, null,
                                                 false);
while ( re.hasNextElement() ) {
  byte b [] = re.nextRecord();
  history += new String(b) + "\n\n";
}
// In destroyApp():
URLStore.closeRecordStore();

— End of Listing —