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

📄 rms_mid.java

📁 小型的数据管理系统RecordStore 可添加、修改
💻 JAVA
字号:
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.rms.*;
import java.io.*;


public class RMS_MID extends MIDlet {

	Display display = Display.getDisplay(this);
	RecordStore rs = null;
	RecordEnumeration re = null;
	Form form = null;
	
	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
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(bos);
		
		try
		{
			rs = RecordStore.openRecordStore("Test", true);
			for(int i=0;i<10;i++)
			{
				dos.writeInt(i * 100);
				System.out.println(rs.addRecord(bos.toByteArray(), 0, bos.toByteArray().length));
				bos.reset();
			}
			re = rs.enumerateRecords(new RecordFilter(){
				public boolean matches(byte[] data) {
					DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data));
					int score = 0;
					
					try{
						score = dis.readInt();
						return score>300;
					}catch(Exception e)
					{
						e.printStackTrace();
						return false;
					}
				}
			}, new RecordComparator(){
				public int compare(byte[] first,byte[] second)
				{
					DataInputStream disF = new DataInputStream(new ByteArrayInputStream(first));
					DataInputStream disS = new DataInputStream(new ByteArrayInputStream(second));
					int f = 0;
					int s = 0;
					
					try
					{
						f = disF.readInt();
						s = disS.readInt();
						
						if(f > s)
						{
							return RecordComparator.FOLLOWS;
						}else if(f < s)
						{
							return RecordComparator.PRECEDES;
						}else
						{
							return RecordComparator.EQUIVALENT;
						}
					}catch(Exception e)
					{
						e.printStackTrace();
						return -1;
					}
				}
			}, false);
//			re = rs.enumerateRecords(null, null, false);
			re.reset();
			System.out.println(re.numRecords());
			while(re.hasNextElement())
			{
				DataInputStream dis = new DataInputStream(new ByteArrayInputStream(re.nextRecord()));
//				System.out.println(re.nextRecordId());
				System.out.println(dis.readInt());
				dis.close();				
			}
			rs.deleteRecord(10);
//			re.rebuild();
			System.out.println(re.numRecords());
			re.destroy();
		}catch(Exception e)
		{
			e.printStackTrace();
		}
	}

}

⌨️ 快捷键说明

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