I have a LWUIT TextArea which accepts user input. After the user hits submit, the string that the user has inputted on the TextArea is saved on the disk. For this purpose, I do:
to ensure that the string is encoded as UTF-8 before persisting it to disk. When reading it from disk, I do:
DataOutputStream daos = new DataOutputStream(baos);
byte data = baos.toByteArray();
rec.addRecord(data, 0, data.length);
to ensure that the string that was encoded as UTF-8 is properly read.
DataInputStream dais = new DataInputStream(bais);
String name = dais.readUTF();
My problem is, if the user inputs an Arabic string on the text area, it would display fine on the screen. Once the user hits submit and I try to read back the string that was saved and display it on the text area, it would not display correctly. Instead, what would be displayed are a bunch of 0's and squares instead of the original Arabic character that the user has inputted. However, if I use Unicode code points to represent a UTF-8 character instead (e.g. \u200f\u0645\u0648\u0627\u0641\u0642), it would display fine on the text area - and this is how I represent Arabic characters in my localization file. Any idea why is this the case? Can we only display Arabic characters on the screen if it is in Unicode code point?