JR 精品文章 - J2ME中RMS的使用解析(二)
AD: jr (at) javaresearch.org


首页 | 动态 | 文章 | FAQ  | 新闻 | 下载 | 代码 | 工作 | 调查 | 术语 | 站点 | 图书 | 论坛 | 帮助 | 全部  

TOP | 交流 | 软件 | 专栏 | 开源 | 译/著 | 源码 | API  | 推荐 | FTP  | 积分 | 统计 | 搜索 | Blog | 我们  
首页 » 研究文集 » J2ME综合 搜索标题相关文章 搜索标题相关文章    评论此文章 发表评论     开始监控此文章 开始监控   加入收藏夹  加入收藏夹
J2ME中RMS的使用解析(二)
lu_-yi 原创   更新:2007-01-11 19:53:56  版本: 1.0   

public int getInt1() { //int 
return int1; 
}
public int getInt2() { 
return int2; 
}
public long getLong1() { 
return long1; 


public String getStr1() { //String 
return str1; 


public String getStr2() { //String 
return str2; 


public String getStr3() { 
return str3; 


public boolean getWroteFlag() { //返回写入标志 
return WroteFlag; 


这个类的使用保证了我们在使用流时,内容的写入和输出。当然,就如同数据库表的设计一样,我们可以任意对每一条记录增加或减少字段,在上面的类中我只使用了int1,int2,long1,str1,str2,str3和WroteFlag一共7个字段。

二、RecordStore的操作。类RMS如下: 
package com.cuilichen.usual; 

import javax.microedition.rms.RecordEnumeration; 
import javax.microedition.rms.RecordStore; 

public class RMS { 
public static final int Int1 = 0;//各个字段的默认数值 
public static final int Int2 = 0; 
public static final long Long1 = 0; 
public static final String Str1 = ""; 
public static final String Str2 = ""; 
public static final String Str3 = ""; 

public static boolean addRecord(String name, int int1, int int2,//添加记录 
long long1, String str1, String str2, String str3, boolean b) { 
boolean success = false; 

try { 
RecordStore rs = RecordStore.openRecordStore(name, true); 
Appointment app = new Appointment(int1, int2, long1, str1, str2,str3, b); 
//既然str1作为保留字段,我们在这里就要如此操作:例如int1为我们设定的关键字,那么str1 = Integer.toString(int1); 
byte[] data = app.toBytes(); 
rs.addRecord(data, 0, data.length); 
rs.closeRecordStore(); 
success = true; 
} catch (Exception e) { 
e.printStackTrace(); 
}
return success; 
}
public static int getNumOfRecords(String name) {//得到RMS中记录的条数 
try { 
RecordStore rs = RecordStore.openRecordStore(name, true); 

return rs.getNumRecords(); 
} catch (Exception e) { 
return 0; 



public static Appointment[] getRecords(String name) {//取得RMS中的所有记录 
Appointment[] result = { }; 

try { 
RecordStore rs = RecordStore.openRecordStore(name, false); 
RecordEnumeration re = rs.enumerateRecords(null, null, false); 
result = new Appointment[rs.getNumRecords()]; 

for (int i = 0; i < result.length; i++) { 
int j = re.previousRecordId(); 
Appointment app = new Appointment(rs.getRecord(j)); 
result = app; 

//System.out.println("app["+i+"] "+app.getStr2()); 


rs.closeRecordStore(); 
} catch (Exception e) { 


return result; 




版权声明   给作者写信
本篇文章对您是否有帮助?  投票:         投票结果:     5       0
作者其它文章: 作者全部文章
评论人:jiandingzw 发表时间: Wed Mar 07 18:23:50 CST 2007
谢谢作者了小弟行礼

这个文章共有 1 条评论
主题: J2ME中RMS的使用解析(三) 上一篇文章
返回文章列表 返回〔J2ME综合〕
下一篇文章 主题: 确保无线 J2ME 的安全


文字广告链接
        自主、快速定制基于JAVA的B/S业务系统          重量级企业在线自定义WEB报表平台
        Excel制表、零代码发布、打印、图表结合——快逸报表,免费、稳定、功能强大的java工具
        技术圈: 关于Java、dotNet、PHP、Ruby、奇客、Web2.0等更多资讯博客精选文章

关于 JR  |  版权声明  |  联系我们 

©2002-2006 JR 版权所有 沪ICP备05019622号