Android URL Download downloadHtmlPage(String pageUrl)

Here you can find the source of downloadHtmlPage(String pageUrl)

Description

download Html Page

Declaration

static String downloadHtmlPage(String pageUrl) 

Method Source Code

//package com.java2s;
import java.io.BufferedInputStream;

import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import org.apache.http.util.ByteArrayBuffer;

public class Main {
    static String downloadHtmlPage(String pageUrl) {
        try {/*from   w  ww  . j a  va  2 s  .c  om*/
            URL url = new URL(pageUrl);
            URLConnection uConn = url.openConnection();
            uConn.setConnectTimeout(15000);
            uConn.setReadTimeout(15000);
            InputStream is = uConn.getInputStream();
            BufferedInputStream bis = new BufferedInputStream(is);
            ByteArrayBuffer baf = new ByteArrayBuffer(65536);
            int current;
            while ((current = bis.read()) != -1)
                baf.append((byte) current);
            return new String(baf.toByteArray(), "Cp1251");
        } catch (Exception e) {
            return null;
        }
    }
}

Related

  1. download(String url, String directoryName, String fileName)
  2. downloadFile(String downloadUrl, String outputFilePath)
  3. downloadFile(URL url, OutputStream output)
  4. downloadUrl(String urlString)
  5. getJSONResponseFromURL(String url, Hashtable httpGetParams)
  6. downloadJson(URI uri)
  7. getURLString(String urlStr)