📄 getrecordmidlet.java
字号:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
// A first MIDlet with simple text and a few commands.
public class getRecordMIDlet extends MIDlet
implements CommandListener {
private Command exitCommand;
//The display for this MIDlet
private Display display;
public getRecordMIDlet() {
display = Display.getDisplay(this);
exitCommand = new Command("离开", Command.STOP, 1);
}
// Start the MIDlet by creating the TextBox and
// associating the exit command and listener.
public void startApp() {
TextBox aTextBox = new TextBox("主画面",null,256,TextField.ANY);
RecordStore rs = null;
byte[] nameEmail=null;
boolean existingOrNot = false;
boolean OK = true;
existingOrNot = existing("aRS");
if(existingOrNot){
try{
rs = RecordStore.openRecordStore("aRS",false);
}
catch(Exception e){
OK = false;
}
finally{
if(OK){
aTextBox.setString("aRS已存在并且已打开");
}
else{
aTextBox.setString("aRS已存在但无法打开");
}
}
}
else{
try{
rs = RecordStore.openRecordStore("aRS",true);
}
catch(Exception e){
OK = false;
}
finally{
if(OK){
aTextBox.setString("aRS虽未存在,但已创建并完成打开的操作!");
}
else{
aTextBox.setString("aRS虽未存在,但无法创建,打开文件失败!");
}
}
}
if(OK)
try{
int number = rs.getNumRecords();
String record="";
String result="共有" + number + "笔记录\n";
int position=0;
for(int i =1;i< rs.getNextRecordID();i++){
record = new String(rs.getRecord(i));
position = record.indexOf('=');
if(position !=-1){
result+="name->" + record.substring(0,position) + "\n" +
"E-mail:" + record.substring(position+1,record.length()) +"\n";
System.out.println(result);
}
}
aTextBox.setString(result);
}
catch(Exception e){
aTextBox.setString("获取记录的操作失败" );
try{
rs.closeRecordStore();
System.out.println("1.Closed.");
RecordStore.deleteRecordStore("aRS");
System.out.println("delete OK");
}
catch(Exception x){
}
}
if(OK)
try{
rs.closeRecordStore();
System.out.println("2.Closed.");
// RecordStore.deleteRecordStore("aRS");
// System.out.println("delete OK");
}
catch(Exception e){
}
aTextBox.addCommand(exitCommand);
aTextBox.setCommandListener(this);
display.setCurrent(aTextBox);
}
// Pause is a no-op because there are no background
// activities or record stores to be closed.
public void pauseApp() { }
// Destroy must cleanup everything not handled
// by the garbage collector.
// In this case there is nothing to cleanup.
public void destroyApp(boolean unconditional) { }
public boolean existing(String recordStoreName) {
boolean existingOrNot = false;
RecordStore rs = null;
if(recordStoreName.length() > 32) return false;
try{
rs = RecordStore.openRecordStore(recordStoreName,false);
}
catch(RecordStoreNotFoundException e){
existingOrNot = false;
}
catch(Exception e){
}
finally{
try{
rs.closeRecordStore();
}
catch(Exception e){
}
}
return existingOrNot;
}
public void commandAction(Command c, Displayable s) {
destroyApp(false);
notifyDestroyed();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -