当前页面: 开发资料首页 → J2ME 专题 → 请教RMS问题,在线等。
请教RMS问题,在线等。
摘要: 请教RMS问题,在线等。
我照着例子
// 写入数据
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
dos.writeUTF("myString");
byte[] data = baos.toByteArray();
rs.addRecord(data,0,data.length);
//读出数据
byte[] data1 = rs.getRecord(1);
ByteArrayInputStream bais = new ByteArrayInputStream(data1);
DataInputStream dis = new DataInputStream(bais);
String myString = dis.readUTF();
为何总是出现d:/WTK22/apps/09/src/CL/CL.java:223: unreported exception java.io.IOException; must be caught or declared to be thrown
dos.writeUTF("myString");
错误啊。
rs open了没有
dos.writeUTF("myString")后面加dos.flush()试试看
我也不懂,随便说说
OPEN了,加了还是不行。
好像是没有进行异常处理
加上throws IOException试试
如果这样
try {
rs = RecordStore.openRecordStore("lRMS", true);
} catch (RecordStoreNotFoundException e) {
e.printStackTrace();
} catch (RecordStoreFullException e) {
e.printStackTrace();
} catch (RecordStoreException e) {
e.printStackTrace();
}
try{
byte[] data1=rs.getRecord(1);
}catch(RecordStoreException e){
System.out.println("Program error!exit");
}
会读取不了数据,显示Program error!exit是什么问题啊。
RecordStoreException - if a general record store exception occurs
try{
if (rs.getNumRecords() > 0)//
{
byte[] data1=rs.getRecord(1);
}
}catch(RecordStoreException e){
System.out.println("Program error!exit");
}