亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 3435 | 回復(fù): 0
打印 上一主題 下一主題

RecordStore(RMS) [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2010-02-22 17:45 |只看該作者 |倒序?yàn)g覽

一 RecordStore(RMS)簡介
    javax.microedition.rms 這個(gè)包提供給J2ME Application一個(gè)小型的數(shù)據(jù)庫, RecordStore就是這個(gè)包的核心。原則上在一個(gè)MIDlet中可以放置多個(gè)RecordStore,同一個(gè)MIDlet suite中可以共享同一個(gè)RecordStore進(jìn)行存取,不同的MIDlet suite不能存取同一個(gè)MIDlet suite。

它的諸多特性如下:  
  在MIDlet suite中每一個(gè)RecordStore的名稱是唯一的,不能重復(fù),而不同的MIDlet suite可以使用同名的RecordStore。
  創(chuàng)建RecordStore名稱時(shí),字母是區(qū)分大小寫的,且名稱字符串不能超過32個(gè)字符。
  
基本存儲(chǔ)讀取模式:
    RecordStore由多條記錄(Record)所組成。

    key1|content;key2|content;key2|content...
    就是 key|content pair, 這個(gè)pair算一條記錄。

創(chuàng)建RecordStore(RMS)對(duì)象
    使用RecordStore.openRecordStore函數(shù),打開一個(gè)存儲(chǔ)對(duì)象并取得句柄rs,然后使用rs.addRecord向存儲(chǔ)對(duì)象中添加記錄,最后關(guān)閉存儲(chǔ)對(duì)象rs.closeRecordStore,完成初始化過程。

view plaincopy to clipboardprint?
public void initRecord(){   
    //--------------------------   
    //--- Initialize RecordStore   
    //--------------------------   
    RecordStore rs = null;   
    String[] strData = null;   
    int n;   
    try{   
        rs = RecordStore.openRecordStore("history", true);   
        strData = new String[]{""};   
  
        // history.1 = history data   
         
        n = strData.length - rs.getNumRecords();   
        for (int i = (strData.length - n); i   
            rs.addRecord(strData.getBytes(), 0, strData.getBytes().length);   
        }   
        rs.closeRecordStore();   
  
    }catch(Exception e){   
        System.out.println("RecInitErr: " + e.toString());   
        if (rs != null){   
            try{   
                rs.closeRecordStore();   
            }catch(Exception e2){}   
        }   
    }   
    strData = null;   
}  
public void initRecord(){
    //--------------------------
    //--- Initialize RecordStore
    //--------------------------
    RecordStore rs = null;
    String[] strData = null;
    int n;
    try{
        rs = RecordStore.openRecordStore("history", true);
        strData = new String[]{""};

        // history.1 = history data
      
        n = strData.length - rs.getNumRecords();
        for (int i = (strData.length - n); i
            rs.addRecord(strData.getBytes(), 0, strData.getBytes().length);
        }
        rs.closeRecordStore();

    }catch(Exception e){
        System.out.println("RecInitErr: " + e.toString());
        if (rs != null){
            try{
                rs.closeRecordStore();
            }catch(Exception e2){}
        }
    }
    strData = null;
}

存儲(chǔ)RecordStore(RMS)對(duì)象
需要一個(gè)索引ID和所需要存儲(chǔ)的內(nèi)容strData,這個(gè)過程需要把整個(gè)RMS打開,尋找擁有這個(gè)索引ID的record。如果找到了,就更新這個(gè)record; 如果沒有,就新建立一個(gè)。

參數(shù)String strName是存儲(chǔ)對(duì)象名

參數(shù)String strData是需要存儲(chǔ)的字符串

參數(shù)int intID是該字符的索引ID

首先,判斷存儲(chǔ)對(duì)象是否存在,如果存在,使用rsWrite.setRecord方法來更新存儲(chǔ)對(duì)象。

view plaincopy to clipboardprint?
public boolean writeRecord(String strName, String strData, int intID){   
    //----------------------------   
    //--- RecordStore的存儲(chǔ)   
    //----------------------------   
    RecordStore rsWrite = null;   
    try{   
        rsWrite = RecordStore.openRecordStore(strName, true);   
        byte[] bytWrite = strData.getBytes();   
        if (rsWrite.getNumRecords() == 0){   
            //--- RecordStore不存在,則生成之   
              rsWrite.addRecord(bytWrite, 0, bytWrite.length);   
        }else{   
            //--- RecordStore更新   
              rsWrite.setRecord(intID, bytWrite, 0, bytWrite.length);   
        }   
        rsWrite.closeRecordStore();   
        return true;   
    }catch(Exception e){   
        if (rsWrite != null){   
            try{   
                rsWrite.closeRecordStore();   
            }catch(Exception e2){}   
        }   
        return false;   
    }   
}  
public boolean writeRecord(String strName, String strData, int intID){
    //----------------------------
    //--- RecordStore的存儲(chǔ)
    //----------------------------
    RecordStore rsWrite = null;
    try{
        rsWrite = RecordStore.openRecordStore(strName, true);
        byte[] bytWrite = strData.getBytes();
        if (rsWrite.getNumRecords() == 0){
            //--- RecordStore不存在,則生成之
              rsWrite.addRecord(bytWrite, 0, bytWrite.length);
        }else{
            //--- RecordStore更新
              rsWrite.setRecord(intID, bytWrite, 0, bytWrite.length);
        }
        rsWrite.closeRecordStore();
        return true;
    }catch(Exception e){
        if (rsWrite != null){
            try{
                rsWrite.closeRecordStore();
            }catch(Exception e2){}
        }
        return false;
    }
}

讀取RecordStore(RMS)對(duì)象
只需要提供 索引ID, 然后打開 RMS 尋找擁有這個(gè)索引ID的record,如果找到了就重組成數(shù)據(jù),不然就是沒有這個(gè)record。

參數(shù)String strName是讀取對(duì)象名

參數(shù)int intID是讀取索引ID

返回值String是需要讀取的字符串

view plaincopy to clipboardprint?
public String readRecord(String strName, int intID){   
    //----------------------------   
    //--- RecordStore的讀取   
    //----------------------------   
    RecordStore rsRead = null;   
    try{   
        rsRead = RecordStore.openRecordStore(strName, false);   
        byte[] bytRead = rsRead.getRecord(intID);   
        rsRead.closeRecordStore();   
        return new String(bytRead);   
    }catch(Exception e){   
        if (rsRead != null){   
            try{   
                rsRead.closeRecordStore();   
            }catch(Exception e2){}   
        }   
        return "";   
    }   
}  
public String readRecord(String strName, int intID){
    //----------------------------
    //--- RecordStore的讀取
    //----------------------------
    RecordStore rsRead = null;
    try{
        rsRead = RecordStore.openRecordStore(strName, false);
        byte[] bytRead = rsRead.getRecord(intID);
        rsRead.closeRecordStore();
        return new String(bytRead);
    }catch(Exception e){
        if (rsRead != null){
            try{
                rsRead.closeRecordStore();
            }catch(Exception e2){}
        }
        return "";
    }
}

說明:
    在J2ME Application/Game中,RMS經(jīng)常用到。一些特殊的參數(shù)或者游戲的狀態(tài)可以用RMS存儲(chǔ)起來, 到用的時(shí)候讀取就行了。


本文來自ChinaUnix博客,如果查看原文請(qǐng)點(diǎn):http://blog.chinaunix.net/u1/49717/showart_2184087.html
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP