BufferedReader doesn't work in arabic (encoding problem)
I want to show an arabic text in a TextView.
It work when i call it in a static form(Call the text from R.string.arabic_text), for this I use some methodes. But whene i want to get the text from an InputStreamReader , it fail.
HttpClient httpclie开发者_StackOverflow中文版nt = new DefaultHttpClient();
HttpPost httppost = new HttpPost(Url);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = ArabicUtilities.reshape(reader.readLine())) != null) {
sb.append(line + "\n");
}
is.close();
result = sb.toString();
The Ulr file
pitures
The text output on the emulator picture was take by an AlertDialog
Utils.AlertTestDeveloppementMsg(result);
and is the same on the Toast
I extract perfectly the field name from the file.
I tried lot of charset in new InputStreamReader(
is, "iso-8859-1")
US-ASCII ,ISO-8859-1,UTF-8,UTF-16BE,UTF-16LE,UTF-16,Cp1256 ..
Http reply has a Content-type
header, which in case of text contents contains also encoding. You are assuming that the reply is encoded in iso-8859-1
.
So you should either manually check what encoding is used in reply or, preferably use EntityUtils.toString()
which automatically check the encoding and converts accordingly:
result = EntityUtils.toString(entity);
精彩评论