【问题标题】:downloaded non-english html file not readable in webview下载的非英文 html 文件在 webview 中不可读
【发布时间】:2013-05-15 22:15:02
【问题描述】:

保存(马拉雅拉姆语)字符串内容代码

    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 传输编码能解决这个问题吗??
请帮忙

【问题讨论】:

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


    【解决方案1】:
            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;
    

    ..
    读取文件并保存以下代码

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

    【讨论】:

    • OStream.write(A[i].getBytes("ISO-8859-1"));
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-07
    • 1970-01-01
    • 2014-04-11
    • 1970-01-01
    • 2020-10-14
    • 1970-01-01
    相关资源
    最近更新 更多