如何存取数据?

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

刚接触手机编程,问题很肤浅,见笑了
...全文
195 点赞 收藏 10
写回复
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,看你设计而定,而且,没有一个方法就能实现的
回复 点赞
发动态
发帖子
J2ME
创建于2007-09-28

1.1w+

社区成员

2.6w+

社区内容

Java J2ME
社区公告
暂无公告