1

how can i insert a UTF-8 String into RecordStore and read this as a UTF-8 String ?

thanks

DJafari
  • 12,955
  • 8
  • 43
  • 65

2 Answers2

2
//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();
takrl
  • 6,356
  • 3
  • 60
  • 69
Alaster
  • 36
  • 2
1

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.

Chris Dennett
  • 22,412
  • 8
  • 58
  • 84