下载文件中的字符错误

时间:2017-04-24 17:00:26

标签: android encoding character

我正在我的应用程序中阅读互联网上的文件:this one

但是,当我试图展示一些文字时,我的口音上出现了错误的字符。 (应用程序显示 而不是“é”或“à”)

我正在使用AsyncTask和BufferReader来读取文件。我该怎么做才能正确阅读?

以下是我用来从互联网上读取文件的方法:

private List<String> allLine = new ArrayList<String>();

private void readListWEBDFD() {
    HttpClient client = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(url);
    try {
        HttpResponse response = client.execute(httpGet);
        StatusLine statusLine = response.getStatusLine();
        int statusCode = statusLine.getStatusCode();
        if (statusCode == 200) {
            HttpEntity entity = response.getEntity();
            InputStream content = entity.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(content));
            String line;
            while ((line = reader.readLine()) != null) {
                allLine.add(line);
            }
        } else {
            Log.e(MainActivity.class.toString(), "Failed to download file");
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

1 个答案:

答案 0 :(得分:0)

看起来InputStreamReader可能默认为ASCII。有一个构造函数,它接受两个参数,你可以像这样声明一个charset:

new InputStreamReader(inputStream, "ISO-8859-1")