相关j2me的存档rms编程的一个问题:我想编写一个类文件,该类文件的功能是将当前java应用的rms读出并显示
相关j2me的存档rms编程的一个问题:我想编写一个类文件,该类文件的功能是将当前java应用的rms读出并显示,请问懂j2me的朋友有什么大体的建议吗?面临的问题是,1...
相关j2me的存档rms编程的一个问题:我想编写一个类文件,该类文件的功能是将当前java应用的rms读出并显示,请问懂j2me的朋友有什么大体的建议吗?面临的问题是,1,如何找到当前应用的存档,并将其所有内容按字符串格式读取;2,如何从canvas中的paint中夺取主线程,先显示我这个类的paint
展开
1个回答
展开全部
你这个问题我还不太清楚,但是跟你分享一下我写的一个rms类,有增、删、改、查四个静态方法,用着挺方便的,希望能帮到你
package com.dd;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import javax.microedition.rms.RecordStoreFullException;
import javax.microedition.rms.RecordStoreNotFoundException;
public class DDStore {
private static RecordStore ddStore = null;
private DDStore() {
}
public static synchronized byte[] getRecord(String name, boolean flag, int i, DDPay pay) {
byte[] res = null;
try {
ddStore = RecordStore.openRecordStore(name, flag);
if (ddStore != null && ddStore.getNumRecords() > 0) {
res = ddStore.getRecord(i);
}
if (ddStore != null) {
ddStore.closeRecordStore();
}
} catch (RecordStoreFullException e) {
pay.onError(111, "error: full rms 2");
} catch (RecordStoreNotFoundException e) {
pay.onError(112, "error: not found rms 2");
} catch (RecordStoreException e) {
pay.onError(113, "error: rms 2");
}
return res;
}
public static synchronized void setRecord(String name, boolean flag, int i, byte[] value, DDPay pay) {
try {
ddStore = RecordStore.openRecordStore(name, flag);
if (value != null && ddStore != null && ddStore.getNumRecords() > 0) {
ddStore.setRecord(i, value, 0, value.length);
}
if (ddStore != null) {
ddStore.closeRecordStore();
}
} catch (RecordStoreFullException e) {
pay.onError(111, "error: full rms 2");
} catch (RecordStoreNotFoundException e) {
pay.onError(112, "error: not found rms 2");
} catch (RecordStoreException e) {
pay.onError(113, "error: rms 2");
}
}
public static synchronized void deleteRecord(String name, boolean flag, int i, DDPay pay) {
try {
ddStore = RecordStore.openRecordStore(name, flag);
if (ddStore != null && ddStore.getNumRecords() > 0) {
ddStore.deleteRecord(i);
}
if (ddStore != null) {
ddStore.closeRecordStore();
}
} catch (RecordStoreFullException e) {
pay.onError(111, "error: full rms 2");
} catch (RecordStoreNotFoundException e) {
pay.onError(112, "error: not found rms 2");
} catch (RecordStoreException e) {
pay.onError(113, "error: rms 2");
}
}
public static synchronized void addRecord(String name, boolean flag, int i, byte[] value, DDPay pay) {
try {
ddStore = RecordStore.openRecordStore(name, flag);
if (value != null && ddStore != null && ddStore.getNumRecords() == 0) {
ddStore.addRecord(value, 0, value.length);
}
if (ddStore != null) {
ddStore.closeRecordStore();
}
} catch (RecordStoreFullException e) {
pay.onError(111, "error: full rms 2");
} catch (RecordStoreNotFoundException e) {
pay.onError(112, "error: not found rms 2");
} catch (RecordStoreException e) {
pay.onError(113, "error: rms 2");
}
}
public static boolean isTrue(String name) {
byte[] res = null;
try {
RecordStore ddStore = RecordStore.openRecordStore(name, true);
if (ddStore != null && ddStore.getNumRecords() > 0) {
res = ddStore.getRecord(1);
} else {
ddStore.addRecord(DDUtils.int2byte(0), 0, DDUtils.int2byte(0).length);
}
if (ddStore != null) {
ddStore.closeRecordStore();
}
} catch (RecordStoreFullException e) {
} catch (RecordStoreNotFoundException e) {
} catch (RecordStoreException e) {
}
if (res != null && res.length > 0) {
return DDUtils.byte2int(res) == 1;
}
return false;
}
}
package com.dd;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import javax.microedition.rms.RecordStoreFullException;
import javax.microedition.rms.RecordStoreNotFoundException;
public class DDStore {
private static RecordStore ddStore = null;
private DDStore() {
}
public static synchronized byte[] getRecord(String name, boolean flag, int i, DDPay pay) {
byte[] res = null;
try {
ddStore = RecordStore.openRecordStore(name, flag);
if (ddStore != null && ddStore.getNumRecords() > 0) {
res = ddStore.getRecord(i);
}
if (ddStore != null) {
ddStore.closeRecordStore();
}
} catch (RecordStoreFullException e) {
pay.onError(111, "error: full rms 2");
} catch (RecordStoreNotFoundException e) {
pay.onError(112, "error: not found rms 2");
} catch (RecordStoreException e) {
pay.onError(113, "error: rms 2");
}
return res;
}
public static synchronized void setRecord(String name, boolean flag, int i, byte[] value, DDPay pay) {
try {
ddStore = RecordStore.openRecordStore(name, flag);
if (value != null && ddStore != null && ddStore.getNumRecords() > 0) {
ddStore.setRecord(i, value, 0, value.length);
}
if (ddStore != null) {
ddStore.closeRecordStore();
}
} catch (RecordStoreFullException e) {
pay.onError(111, "error: full rms 2");
} catch (RecordStoreNotFoundException e) {
pay.onError(112, "error: not found rms 2");
} catch (RecordStoreException e) {
pay.onError(113, "error: rms 2");
}
}
public static synchronized void deleteRecord(String name, boolean flag, int i, DDPay pay) {
try {
ddStore = RecordStore.openRecordStore(name, flag);
if (ddStore != null && ddStore.getNumRecords() > 0) {
ddStore.deleteRecord(i);
}
if (ddStore != null) {
ddStore.closeRecordStore();
}
} catch (RecordStoreFullException e) {
pay.onError(111, "error: full rms 2");
} catch (RecordStoreNotFoundException e) {
pay.onError(112, "error: not found rms 2");
} catch (RecordStoreException e) {
pay.onError(113, "error: rms 2");
}
}
public static synchronized void addRecord(String name, boolean flag, int i, byte[] value, DDPay pay) {
try {
ddStore = RecordStore.openRecordStore(name, flag);
if (value != null && ddStore != null && ddStore.getNumRecords() == 0) {
ddStore.addRecord(value, 0, value.length);
}
if (ddStore != null) {
ddStore.closeRecordStore();
}
} catch (RecordStoreFullException e) {
pay.onError(111, "error: full rms 2");
} catch (RecordStoreNotFoundException e) {
pay.onError(112, "error: not found rms 2");
} catch (RecordStoreException e) {
pay.onError(113, "error: rms 2");
}
}
public static boolean isTrue(String name) {
byte[] res = null;
try {
RecordStore ddStore = RecordStore.openRecordStore(name, true);
if (ddStore != null && ddStore.getNumRecords() > 0) {
res = ddStore.getRecord(1);
} else {
ddStore.addRecord(DDUtils.int2byte(0), 0, DDUtils.int2byte(0).length);
}
if (ddStore != null) {
ddStore.closeRecordStore();
}
} catch (RecordStoreFullException e) {
} catch (RecordStoreNotFoundException e) {
} catch (RecordStoreException e) {
}
if (res != null && res.length > 0) {
return DDUtils.byte2int(res) == 1;
}
return false;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询