首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

运用rms工具类存储对象

2012-09-04 
使用rms工具类存储对象//RMS工具类private void writeRMS(){try {RecordStore rsRecordStore.openRecordS

使用rms工具类存储对象
//RMS工具类

private void writeRMS(){try {RecordStore rs=RecordStore.openRecordStore("app", true);ByteArrayOutputStream bos=new ByteArrayOutputStream();DataOutputStream dos=new DataOutputStream(bos);for(int i=0;i<point.length;i++){for(int j=0;j<point[0].length;j++){dos.writeByte(point[i][j]);}}byte[] data=bos.toByteArray();if(rs.getNumRecords()==0){rs.addRecord(data, 0, data.length);}else{rs.setRecord(1, data, 0, data.length);}dos.close();bos.close();rs.closeRecordStore();} catch (RecordStoreFullException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (RecordStoreNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (RecordStoreException e) {// TODO Auto-generated catch blocke.printStackTrace();}catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}private void readRMS(){try {RecordStore rs=RecordStore.openRecordStore("app", true);if(rs.getNumRecords()==0){System.out.println("没有记录");}else{byte[] data=rs.getRecord(1);ByteArrayInputStream bis=new ByteArrayInputStream(data);DataInputStream dis=new DataInputStream(bis);for(int i=0;i<point.length;i++){for(int j=0;j<point[0].length;j++){point[i][j]=dis.readByte();}}dis.close();bis.close();rs.closeRecordStore();}} catch (RecordStoreFullException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (RecordStoreNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (RecordStoreException e) {// TODO Auto-generated catch blocke.printStackTrace();}catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}

热点排行