在模拟器上显示很正常的RMS操作,安装在真机上后就以乱码显示了.
google后发现了这是一个普遍的问题.现在将解决方法记录下来.
//往RMS中保存中文字符串
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
dos.writeUTF(strSave);//strSave 是需要保存的中文字符串
byte[] strbyte = bos.toByteArray();
rs.addRecord(strbyte, 0, strbyte.length); //往RMS中添加记录
//从RMS中读取数据
en=rs.enumerateRecords(null,null,false);
while(en.hasNextElement())
{
int id=en.nextRecordId();
byte b[] = rs.getRecord(id);
DataInputStream dis=new DataInputStream(new ByteArrayInputStream(b));
String strTemp= dis.readUTF();
index++;
strListAll[index]=strTemp;
dis.close();
}
这个和联网程序中采用writeUTF()和readUTF()配对使用时一样的.