如何下载html源码android

时间:2014-03-02 19:12:54

标签: android html

我想从这个网站下载html源代码" www.varzesh3.com"用android 但它并没有在' str'中显示任何内容。变量 这是我的代码:

private String DownloadText2(String URL)
{
    int BUFFER_SIZE = 2048;
    InputStream in = null;
    try {
        in = OpenHttpConnection(URL);
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        //e1.printStackTrace();
        return "";
    }

    InputStreamReader isr = new InputStreamReader(in);
    int charRead;
    String str = "";
    char[] inputBuffer = new char[BUFFER_SIZE];
    try {
        while ((charRead = isr.read(inputBuffer))>0)
        {
            //---convert the chars to a String---
            try{
                String readString =
                        String.copyValueOf(inputBuffer, 0, charRead);
                str += readString;
                inputBuffer = new char[BUFFER_SIZE];
            }
            catch (Exception ex){}
        }
        in.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return "";
    }
    return str;
}

0 个答案:

没有答案