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

📄 enumerationrecord.java

📁 jBuilderX无线应用开发源代码
💻 JAVA
字号:
import javax.microedition.midlet.*;
import javax.microedition.rms.*;
import javax.microedition.lcdui.*;
import java.io.*;

public class EnumerationRecord extends MIDlet {
	private	RecordStore	rs;              
	private RecordEnumeration re;       //声明RecordEnumeration
	private	Display	display;
	private ByteArrayInputStream bis;
	private DataInputStream dis;
	
	public EnumerationRecord () {
		rs = null;
		//将re初始化为null
		re = null;
		display	= Display.getDisplay(this);
	}
	
	public void	startApp() {
		try	{
			rs = RecordStore.openRecordStore("myRecordStore", false);
			//创建RecordEnumeration实例
			re = rs.enumerateRecords(null, null, true);
			//取得记录数
            System.out.println("There are " + re.numRecords() + " records in RecordStore");   
        
        	//顺序读取记录
			while (re.hasNextElement())
            {
                //将数据读入到字节数组b中
                byte [] temp = re.nextRecord();
                bis = new ByteArrayInputStream(temp);
		        dis = new DataInputStream(bis);
		        System.out.println(dis.readUTF());
                System.out.println("--------------------");
            }
           	//逆序读取记录
			while (re.hasPreviousElement())
            {
                //将数据读入到字节数组b中
                byte [] temp = re.previousRecord();
                bis = new ByteArrayInputStream(temp);
		        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){
		try{
			bis.close();
			dis.close();
		}catch(Exception e){
			System.out.println("Error: " + e.getMessage());
		}
	}
}
		

			
				

⌨️ 快捷键说明

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