how can i insert a UTF-8
String into RecordStore and read this as a UTF-8
String ?
thanks
how can i insert a UTF-8
String into RecordStore and read this as a UTF-8
String ?
thanks
//write
ByteArrayOutputStream boStream = new ByteArrayOutputStream();
DataOutputStream doStream = new DataOutputStream(boStream);
doStream.writeUTF(myString);
temp.addRecord(boStream.toByteArray(), 0, boStream.size());
//read
ByteArrayInputStream biStream = new ByteArrayInputStream(temp.getRecord(id));
DataInputStream diStream = new DataInputStream(biStream);
myString = diStream.readUTF();
I got the handle wrong on the question. RecordStore
still store byte arrays. What you need to do is convert it into a byte array and back again. Just use string.getBytes()
and then store it like that, and then the opposite is String str = new String(bytes);
. Hope that helps. The default charset of either J2ME or J2SE is UTF-8, so there's no messing about there.