下载的非英语html文件在webview中无法读取

时间:2013-05-21 08:06:28

标签: android character-encoding webview download utf-32

save(malayalam)字符串内容代码

    String A = "<html><head><style>"
            + "@font-face { font-family: Manorama;src: url(file:///android_asset/Manorama.ttf); }"
            + "h1 { color: #222;font-size: 26px;margin-top: 32px; }"
            + "</style></head><body><h1>"
            + "<font face=\"Manorama\">ØíxàW ¥çÄÞùßxßÏßW 190 æd¿ÏßÈß</font><!--3546062932-->"
            + "</p><body></html>";

    FileOutputStream OStream = null;
    try {
        OStream = openFileOutput("0.html", Context.MODE_PRIVATE);
        OStream.write(A.getBytes("UTF-32"));
        OStream.close();
    } catch (Exception e) {
    }

它完美地工作

但是当我从服务器下载后执行相同的操作时它不起作用(字符在webview中不可读),

找到下面的代码,

        HttpClient client = new DefaultHttpClient();
        HttpResponse response = null;
        InputStream in = null;
        try {
            response = client.execute(new HttpGet(
                    "http://tinymail.in/mail_pipe/thozhilveedhi/pull"));
            in = response.getEntity().getContent();
        } catch (Exception e) {
        }
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(in));
        StringBuilder string = new StringBuilder();
        String line = null;
        try {
            while ((line = reader.readLine()) != null) {
                string.append(line);
            }
            in.close();
        } catch (Exception e) {
        }

        String[] A = (string.toString()).split("__");

        for (int i = 0; i < A.length; i++) {
            if (A[i] != "") {

                try {
                    FileOutputStream OStream = openFileOutput(i + ".html",
                            Context.MODE_PRIVATE);
                    OStream.write(A[i].getBytes("UTF-32"));
                    OStream.close();
                } catch (Exception e) {
                }

            }
        }

我认为问题是从服务器到android的数据传输,我能做什么? base 64传输编码是否解决了这个问题? 请帮忙

1 个答案:

答案 0 :(得分:0)

        HttpClient client = new DefaultHttpClient();
        HttpResponse response = null;

        try {
            response = client.execute(new HttpGet(
                    "http://tinymail.in/mail_pipe/thozhilveedhi/pull"));
        } catch (Exception e) {
        }

        HttpEntity entity = response.getEntity();
        if (entity != null) {

            String data = EntityUtils.toString(entity);
            String[] A = null;

..
阅读文件&amp;以下代码保存

                    try {
                        FileOutputStream OStream = openFileOutput(i
                                + ".html", Context.MODE_PRIVATE);
                        OStream.write(A[i].getBytes("UTF-16"));
                        OStream.close();
                    } catch (Exception e) {
                    }

                }
            }

        }