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

📄 readrecord.java

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

public class ReadRecord extends MIDlet	implements CommandListener{
	//声明一个RecordStore对象
	private	RecordStore	rs;
	private	Display	display;
	private	TextBox	t;
	private	Command	exit;
	private	ByteArrayInputStream bis;		//字节数组输入流
	private	DataInputStream dis;			//数据输入流
	private	byte b[];					//字节数组
	private int i;                      		//循环变量
	
	public ReadRecord () {
		//将rs初始化为null
		rs = null;
		display	= Display.getDisplay(this);
		exit = new Command("exit", Command.EXIT, 2);
		t = new TextBox("Message", "Read completed!", 256, 0);
		b = new byte[256];
		bis	= new ByteArrayInputStream(b);
		dis	= new DataInputStream(bis);
	}
	
	public void	startApp() {
		try	{
			//打开记录存储myRecordStore
			rs = RecordStore.openRecordStore("myRecordStore", false);
			//使用循环读入记录
			for (i = 1; i <= rs.getNumRecords()-1; i++)
            	{
              	  //将数据读入到字节数组b中
              	  rs.getRecord(i, b, 0);
              	  //输出数据
              	  System.out.println("Record #" + i);
              	  System.out.println("String: " + dis.readUTF());
              	  System.out.println("--------------------");
              	  // 清空输入流
              	  bis.reset();
            	}
            	//读取最后一条记录
            	bis.reset();
            	rs.getRecord(i, b, 0);
           	System.out.println("Record #" + i);
            	System.out.println("Name: " + dis.readUTF());
            	System.out.println("Tel: " + dis.readUTF());
            	System.out.println("Sex: " + dis.readBoolean());
            	System.out.println("Age: " + dis.readInt());
            	System.out.println("--------------------");
                    
			t.addCommand(exit);
			t.setCommandListener(this);
			display.setCurrent(t);
		}catch(Exception e){
			System.out.println("Error: " + e.getMessage());
		}
		
		//关闭记录存储集
		try{
			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());
		}
	}
	
	public void	commandAction(Command c, Displayable s)	{
		if(c ==	exit) {
			destroyApp(false);
			notifyDestroyed();
		}
	}
}

⌨️ 快捷键说明

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