Java URL Download downloadPageSource(String stringURL)

Here you can find the source of downloadPageSource(String stringURL)

Description

download Page Source

License

Open Source License

Declaration

public static String downloadPageSource(String stringURL) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import java.net.HttpURLConnection;
import java.net.URL;

public class Main {
    public static String downloadPageSource(String stringURL) throws IOException {
        URL url;//from  w w  w . j ava 2s . c  o  m
        HttpURLConnection conn;
        StringBuilder source = new StringBuilder();

        try {
            url = new URL(stringURL);
            conn = (HttpURLConnection) url.openConnection();
        } catch (IOException ex) {
            throw ex;
        }

        try {
            String line;
            conn.setRequestMethod("GET");
            BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            while ((line = in.readLine()) != null)
                source.append(line);
        } catch (IOException ex) {
            throw ex;
        } finally {
            conn.disconnect();
        }

        return source.toString();
    }
}

Related

  1. downloadFromUrl(URL url, String localFilename)
  2. downloadGzipCompressedFile(URL url, File destination)
  3. downloadHttp(String downloadURL, String basePath, String commonPathURL)
  4. downloadImg(String urlPath, File file)
  5. downloadMobiFromEpubUrl(String href)
  6. downloadSource(PrintStream out, PrintStream err, String srcURL, String dirStr, boolean extract)
  7. downloadString(String url)
  8. downloadString(URL url)
  9. downloadString(URL url)