在j2me中,rms的条件过滤主要是用到了RecordFilter接口,必须实现里面的public boolean matches(byte[] candidate)方法 例子: 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; public class testSearch extends MIDlet { private RecordStore rs = null; // Record store private static final String REC_STORE = "db_2"; // Name of Record Store 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 openRecStore(); writeTestData(); searchRecordStore(); closeRecStore(); } public void openRecStore() { try { // Create Record Store if it does not exist rs = RecordStore.openRecordStore(REC_STORE, true); } catch (Exception e) { e.printStackTrace(); } } public void closeRecStore() { try { rs.closeRecordStore(); } catch (Exception e) { } } public void writeTestData() { String[] golfClubs = { "BeiJing...The capital of my matherland", "UESTC...University of Electronical Science and Technology of China", "J2ME is a good sofrware" }; writeRecords(golfClubs); } public void writeRecords(String[] sData) { byte[] record; try { if (rs.getNumRecords() > 0) return; for (int i = 0; i < sData.length; i++) { record = sData[i].getBytes(); rs.addRecord(record, 0, record.length); } } catch (Exception e) { e.printStackTrace(); } } private void searchRecordStore() { try { if (rs.getNumRecords() > 0) { SearchFilter search = new SearchFilter("beijin"); //此处是查询条件,该方法为模糊查询 RecordEnumeration re = rs.enumerateRecords(search, null, false); if (re.numRecords() > 0) System.out.println(new String(re.nextRecord())); re.destroy(); } } catch (Exception e) { } } class SearchFilter implements RecordFilter { private String searchText = null; public SearchFilter(String searchText) { this.searchText = searchText.toLowerCase(); } public boolean matches(byte[] candidate) { String str = new String(candidate).toLowerCase(); if (searchText != null && str.indexOf(searchText) != -1) return true; else return false; } } }