如何存取数据?

yoci 2007-07-02 04:56:15
用户输入的数据需要保存,请问用什么函数可以实现,谢谢

刚接触手机编程,问题很肤浅,见笑了
...全文
274 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
herooomouse 2007-07-04
  • 打赏
  • 举报
回复
要是怕数据会太多,不如考虑将数据传输到服务器上
yoci 2007-07-03
  • 打赏
  • 举报
回复
RMS中的数据多了会不会影响速度?
「已注销」 2007-07-03
  • 打赏
  • 举报
回复
RMS当然可以长久了,只要手机不坏,软件不删,RMS就一直存在

要想保存成文件也可以,但是需要手机支持JSR75
yoci 2007-07-03
  • 打赏
  • 举报
回复
谢谢各位的帮助,还想问一下如果保存成文件应该怎么样实现
因为数据日积月累会比较多,放在RMS不是长久之计
sisihj 2007-07-03
  • 打赏
  • 举报
回复
RMS占用的内存空间,如何存储空间过大,应该会影响手机性能。不过,RMS能够占用的空间和手机有关。有些手机有限制,如S40。有些则没有限制,只和手机的存储空间相关。
lubin1119 2007-07-02
  • 打赏
  • 举报
回复
import javax.microedition.rms
int i;//record index
byte[] data;//record data
int offset;//record start bit position
int length;//record length (bit)
init data(){
//init data;
}
length = data.length();
RecordStore rs = RecordStore.setRecord(1, data, offset, length); //add a new record
angelleecash 2007-07-02
  • 打赏
  • 举报
回复
class RMS {
static String missionRMS = "MISSION_RMS";
public RMS() {

}
void storeTask(Task task) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
try {
// write task info
dos.writeInt(task.id);
dos.writeUTF(task.label);
dos.writeUTF(task.description);
dos.writeUTF(task.rewardInfo);
dos.writeInt(task.price);
// write components info
TaskComponent[] taskComponents = task.taskComponents;
int numTaskComponents = taskComponents.length;
dos.writeInt(numTaskComponents);
for (int i = 0; i < numTaskComponents; i++) {
TaskComponent component = taskComponents[i];
NPC npc = component.npc;
// write npc info in this component
dos.writeInt(npc.id);
dos.writeInt(npc.countryID);
dos.writeInt(npc.sex);
dos.writeInt(npc.ai);
dos.writeInt(npc.level);
dos.writeUTF(npc.name);
// component info
dos.writeInt(component.numWinTimes);
dos.writeInt(component.shouldWinSequentially);
}
byte data[] = baos.toByteArray();
RecordStore rs = openRecordStore();
if (rs != null) {
if (rs.getNumRecords() <= 0) {
rs.addRecord(data, 0, data.length);
System.out.println("Adding new record");
} else {
rs.setRecord(1, data, 0, data.length);
System.out.println("updating record");
}
rs.closeRecordStore();
System.out.println("Task saved successfully.");
}
} catch (Exception e) {
e.printStackTrace();
}
}
Task getTask() {
try {
RecordStore rs = openRecordStore();
if (rs == null || rs.getNumRecords() <= 0) {
if (rs != null) {
rs.closeRecordStore();
}
return null;
} else {
byte[] data = rs.getRecord(1);
ByteArrayInputStream bais = new ByteArrayInputStream(data);
DataInputStream dis = new DataInputStream(bais);
int id, price, numComponents;
String label, description, rewardInfo;
TaskComponent[] taskComponents;
id = dis.readInt();
label = dis.readUTF();
description = dis.readUTF();
rewardInfo = dis.readUTF();
price = dis.readInt();
System.out.println("id :" + id);
System.out.println("label :" + label);
System.out.println("description :" + description);
System.out.println("rewardInfo" + rewardInfo);
// components
numComponents = dis.readInt();
taskComponents = new TaskComponent[numComponents];
for (int i = 0; i < numComponents; i++) {
int npcID, npcCountryID, npcSex, npcAI, npcLevel, numWinTimes, shouldWinSequentially;
String npcName;
npcID = dis.readInt();
npcCountryID = dis.readInt();
npcSex = dis.readInt();
npcAI = dis.readInt();
npcLevel = dis.readInt();
npcName = dis.readUTF();
numWinTimes = dis.readInt();
shouldWinSequentially = dis.readInt();
System.out.println("npcID :" + npcID);
System.out.println("npcCountryID :" + npcCountryID);
System.out.println("npcSex :" + npcSex);
System.out.println("npcAI :" + npcAI);
System.out.println("npcLevel :" + npcLevel);
System.out.println("npcName :" + npcName);
System.out.println("numWinTimes :" + numWinTimes);
System.out.println("shouldWinSequentially :" + shouldWinSequentially);
taskComponents[i] = new TaskComponent(new NPC(npcID, npcName, npcCountryID, npcSex, npcAI, npcLevel, null), numWinTimes, shouldWinSequentially);
}
rs.closeRecordStore();
return new Task(0, id, price, label, description, rewardInfo, taskComponents);
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
void removeTask() {
try {
RecordStore.deleteRecordStore(missionRMS);
} catch (RecordStoreNotFoundException e) {
e.printStackTrace();
} catch (RecordStoreException e) {
e.printStackTrace();
}
}
RecordStore openRecordStore() {
RecordStore rs = null;
try {
rs = RecordStore.openRecordStore(missionRMS, true);
} catch (RecordStoreFullException e) {
e.printStackTrace();
} catch (RecordStoreNotFoundException e) {
e.printStackTrace();
} catch (RecordStoreException e) {
e.printStackTrace();
}
return rs;
}

}
「已注销」 2007-07-02
  • 打赏
  • 举报
回复
Package javax.microedition.rms

用于进行存储的包,负责数据的存取
yoci 2007-07-02
  • 打赏
  • 举报
回复
能举个例子么?谢谢
yanhan0615 2007-07-02
  • 打赏
  • 举报
回复
要看你保存在什么地方,你可以保存到文件,也可以保存到RMS,看你设计而定,而且,没有一个方法就能实现的

13,097

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧