import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.rms.RecordEnumeration;
import javax.microedition.rms.RecordFilter;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import javax.microedition.rms.RecordStoreFullException;
import javax.microedition.rms.RecordStoreNotFoundException;
public class recordFilter extends MIDlet implements RecordFilter{
RecordStore rs=null;
public recordFilter() {
// TODO Auto-generated constructor stub
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
try {
rs=RecordStore.openRecordStore("rs", true);
rs.addRecord("龙".getBytes(), 0, 2);
rs.addRecord("虎".getBytes(), 0, 2);
rs.addRecord("狍".getBytes(), 0, 2);
rs.addRecord("蛇".getBytes(), 0, 2);
rs.addRecord("老鼠".getBytes(), 0, 4);
rs.deleteRecord(4);
//方法一,枚举遍历
RecordEnumeration re= rs.enumerateRecords(this, null, false); //能发现失效的ID并自动跳过
while(re.hasNextElement())
{
System.out.println(new String(re.nextRecord()));
}
rs.closeRecordStore();
} catch (RecordStoreFullException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RecordStoreNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RecordStoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public boolean matches(byte[] arg0) {
// TODO Auto-generated method stub
if(new String(arg0).startsWith("老")) //过滤第一个字符为“老”的记录
return false;
return true;
}
}