?? midlet1.java
字號(hào):
package prj16_1;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.rms.RecordEnumeration;
import javax.microedition.rms.RecordStore;
public class MIDlet1 extends MIDlet {
protected void startApp() throws MIDletStateChangeException {
RecordStore rs = null;
try{
rs = RecordStore.openRecordStore("RS1", true);
rs.addRecord("中國".getBytes(), 0, 4);
rs.addRecord("美國".getBytes(), 0, 4);
rs.addRecord("韓國".getBytes(), 0, 4);
rs.addRecord("日本".getBytes(), 0, 4);
rs.addRecord("德國".getBytes(), 0, 4);
//getNextRecordId遍歷
rs.deleteRecord(3);
int nextId = rs.getNextRecordID();
for(int i=1;i<nextId;i++){
try{
System.out.println(new String(rs.getRecord(i)));
}catch(Exception ex){}
}
/*枚舉遍歷,能夠自動(dòng)發(fā)現(xiàn)并判斷被刪除的紀(jì)錄,性能較好
rs.deleteRecord(3);
RecordEnumeration re = rs.enumerateRecords(null, null, false);
while(re.hasNextElement()){
System.out.println(new String(re.nextRecord()));
}*/
/*遍歷,以下代碼錯(cuò)誤
rs.deleteRecord(3);
int num = rs.getNumRecords();
for(int i=1;i<=num;i++){
System.out.println(new String(rs.getRecord(i)));
}*/
}catch(Exception ex){
ex.printStackTrace();
}
finally{
try{
rs.closeRecordStore();
}catch(Exception ex){}
}
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -