I have a JSON array that I want to write it into a file. Everything works perfectly about writing the file but the problem is when I try to read it gives me a lot of uncoded text as ……. The text is in Arabic language.
This is my code to read the file:
FileInputStream fis = openFileInput("File");
BufferedInputStream bis = new BufferedInputStream(fis);
StringBuffer sb = new StringBuffer();
while(bis.available() != 0){
char c = (char) bis.read();
sb.append(c);
}
JSONArray read = new JSONArray(sb.toString());
for(int x = 0; x < read.length(); x++){
JSONObject readOb = read.getJSONObject(x);
String id = readOb.getString("id");
String name = readOb.getString("name");
Toast.makeText(Main.this, "Id: " + id + "Name: " + name , Toast.LENGTH_LONG).show();
}
bis.close();
fis.close();
It would be great if anybody would suggest any solution to make text appear perfectly.
Edit:
This is what I tried to append it to StringBuffer.
fis = openFileInput("Test");
InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
StringBuffer sb = new StringBuffer();
while(isr.read() != 0){
sb.append(isr.read());
}