日期:2014-05-20  浏览次数:21107 次

打开RecordStore后,如何关闭它
在接收短信的时候,将接收到的短信存储到RecordStore后,再打开RecordStore读取记录后却不能再关闭它,调试时出现如下提示:unreachable   statement,错误的位置是下面代码中的第二个rs.closeRecordStore();  


public   void   initfile(String   addr,String   cont){//将接收到的信息储存到RMS中
                  String   fileName   = "mydatabase ";
                          try{
                                  rs   =RecordStore.openRecordStore(fileName,true);  
                                  byte[]   array1   =addr.getBytes();
                                  byte[]   array2   =cont.getBytes();
                                  int   recordID1   =rs.addRecord(array1,0,   array1.length);
                                  int   recordID2   =rs.addRecord(array2,   0,array2.length);
                                  rs.closeRecordStore();
                              }catch(RecordStoreNotOpenException   e){
                                      e.printStackTrace();
                              }catch(RecordStoreException   ex){
                                      ex.printStackTrace();
                              }
      }
     
      public   String[]   getRecordd(){   //读取RMS中的记录
              try{
                      rs   =RecordStore.openRecordStore(fileName,true);
                      RecordEnumeration     re   =rs.enumerateRecords(null,null,false);
                      if(re.numRecords()   <=   0){
                              return   null;
                      }else{
                              String[]   result   =new   String[re.numRecords()];//声明并创建数组
                              int   i=0;
                              while(re.hasNextElement()){
                                      result[i++]   =new   String(re.nextRecord());