开发者

how to check first value in rms is null in j2me?

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();    
r开发者_开发知识库s.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();

in this i want to check whether rms contains first value or not, otherwise it will enter new value in it??? But i am still little bit confused that whether information going to stay permanent in mobile or not...


An information permanently stored in RMS and We are already discussed regards this. See this sample code and try like this,

    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 {
    ...
     }
    }

Updates

See these links for your reference,

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜