在j2me中如何检查rms中的第一个值是null?

时间:2011-02-23 11:42:43

标签: java-me mobile rms

RecordStore rs = RecordStore.openRecordStore("StoryDataBase1",true);
String data_to_write_in_file = Slug.getString()+"^"+title.getString()+"^"+Body.getString()+"^"+com.editorial.Main.MainImagePath+"^"+com.editorial.Main.MainVideoPath+"^"+com.editorial.Main.MainVoicePath+"$";

byte b[] = rs.getRecord(1);
String str = new String(b,0,b.length);
if(str.equals("")) {
byte bytes[] = data_to_write_in_file.getBytes();    
rs.addRecord(bytes,0,bytes.length);
}
else
{
str=str+data_to_write_in_file;
byte[] data = str.getBytes();
rs.setRecord(1, data, 0, data.length);
}    
rs.closeRecordStore();

在这里我想检查rms是否包含第一个值,否则它将在其中输入新值???但我仍然有点担心,信息是否会永久保留在移动设备中......

1 个答案:

答案 0 :(得分:1)

永久存储在RMS中的信息我们已经讨论过这个问题。 请参阅此示例代码并尝试这样,

    byte[] recData = null;
    int len;
    RecordStore rs = RecordStore.openRecordStore("StoryDataBase1", true);

    if (rs.getNumRecords() > 0) {
    recData = new byte[rs.getRecordSize(1)];
    len = rs.getRecord(1, recData, 0);
    String value = new String(recData, 0, len);
    if(value == null) {
    ....
    } else {
    ...
     }
    }

<强>更新

请参阅这些链接以供参考,

  1. Persistent Data in Java ME
  2. How to use RMS in j2me