J2ME中将文本中的数据导入RMS
public String getTextByUTF(String name){
String strReturn = "";
int ic;
InputStream in = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
byte[] myData;
byte[] buffer = new byte[1024];
try{
in = getClass().getResourceAsStream(name);
if(in!=null){
while ( (ic = in.read(buffer)) > 0) {
dos.write(buffer,0,ic);
}
myData = baos.toByteArray();
strReturn = new String(myData, "UTF-8");
in.close();
}
dos.close();
baos.close();
}catch(Exception e){
System.out.println("getTextByUTF Error:"+e.toString());
}finally{
in = null;
dos = null;
baos = null;
}
return strReturn;
}
boolean writeInfoToDB(String info,String dbName){
boolean reValue = false;
RecordStore db = NULL;
if (dbName.length() > 32)
return reValue;
try
{
db = RecordStor.openRecordStor(dbName,true);
}catch(Exception e)
{
return reValue;
}
byte[] data = null;
try{
data = info.getBytes("UTF-8");
}catch(Exception e){
System.out.println("getBytes Error:"+e.toString());
}
try{
db.addRecord(data, 0, data.length);
reValue = true;
}catch(Exception e){
}
return reValue;
}

浙公网安备 33010602011771号