⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myfilter.java

📁 jBuilderX无线应用开发源代码
💻 JAVA
字号:
import javax.microedition.midlet.*;
import javax.microedition.rms.*;
import javax.microedition.lcdui.*;
import java.io.*;
//********************************************************
// 过滤器类
//********************************************************
class Filter implements RecordFilter  {
	public boolean matches(byte[] candidate){
	    boolean result = false;
		DataInputStream dis = new DataInputStream(new ByteArrayInputStream(candidate));
		try{
		   String str = dis.readUTF();
		   result = str.startsWith("Second");
	   }
	   catch(Exception e){
	   }
	   if(result) return true;
	   else return false;
	}
}

public class MyFilter extends MIDlet {
    private RecordStore rs;              
    private RecordEnumeration re;   //枚举器
    private Filter rf;              //过滤器
    private Display display;
    
    public MyFilter () {
        rs = null;                  //RecordStore
        re = null;                  //RecordEnumeration
        rf = new Filter();          //RecordFilter
        display = Display.getDisplay(this);
    }
    
    public void startApp() {
        try {
            rs = RecordStore.openRecordStore("myRecordStore", false);
            //创建带有过滤器的枚举器实例
            re = rs.enumerateRecords(rf, null, false);
            System.out.println("There are " + re.numRecords() + " records");   
            while (re.hasNextElement())
            {
                byte [] temp = re.nextRecord();
                ByteArrayInputStream bis = new ByteArrayInputStream(temp);
                DataInputStream dis = new DataInputStream(bis);
                System.out.println(dis.readUTF());
                System.out.println("--------------------");
            }
        }catch(Exception e){
            System.out.println("Error: " + e.getMessage());
        }
        
        try{
            //释放RecordEnumeration所占用的资源
            re.destroy();
            rs.closeRecordStore();
        }catch(Exception e){
            System.out.println("Error: " + e.getMessage());
        }
    }
        
    public void pauseApp(){
    }
    
    public void destroyApp(boolean unconditional){
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -