My J2ME application has to read files in different languages (English, French, Arabic).
The files are written with UTF-8 encoding, and I read them with this code:
InputStream is = this.getClass().getResourceAsStream("/res/traduct_"+ lang +".txt");
StringBuffer sb = new StringBuffer();
int chars;
while ((chars = is.read()) != -1)
sb.append((char) chars);
String str = new String(String.valueOf(sb).getBytes("ISO-8859-1"));
This works fine in Netbeans emulator and also in my LG phone, but in other phones (Nokia, Samsung), Arabic and French are not displayed. Only English works in all cases.
Is there something wrong with my code?
This code is working with no problems : Reading text file in J2ME
String content = "";
Reader in = new InputStreamReader(this.getClass().getResourceAsStream("asdf.txt"), THE_ENCODING);
StringBuffer temp = new StringBuffer(1024);
char[] buffer = new char[1024];
int read;
while ((read=in.read(buffer, 0, buffer.len)) != -1) {
temp.append(buffer, 0, read);
}
content = temp.toString().
Thanks Thilo.