import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordEnumeration;
import javax.microedition.rms.RecordStoreException;
try {
String str;
    //      "Test Storage"
    RecordStore recordStore = RecordStore.openRecordStore
                              ("Test Storage", true);
    //    
    RecordEnumeration re = recordStore.enumerateRecords(null, null, false);
    //    5 ,   
    for(int i=1;i<=5;i++) {
        str = "String no " + i;
        int id = recordStore.addRecord(str.getBytes(),0,str.length());
        System.out.println(str+" was stored with recordID = "+id);
    }
    //  
    re.rebuild();
            
    //       
    while (re.hasNextElement()) {
        int id = re.nextRecordId();
        str = new String(recordStore.getRecord(id));
        System.out.println("RecordID = "+id+": "+str);
    }

    //     
    re.reset();
            
    //    
    for (int i=1; i<=re.numRecords(); i++) { 
        str = new String(re.previousRecord());
        System.out.println("Record: "+str);
    }

    //   
    re.destroy();
    
    //   
    recordStore.closeRecordStore();

} catch(RecordStoreException rse){
         System.out.println(rse.getMessage());
}
