Java URL Read getHtml(String urlString)

Here you can find the source of getHtml(String urlString)

Description

get Html

License

Open Source License

Declaration

public static String getHtml(String urlString) 

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 getHtml(String urlString) {

        if (urlString.contains("id")) {
            StringBuilder html = new StringBuilder();
            InputStreamReader isr = null;
            BufferedReader br = null;
            try {

                URL url = new URL(urlString);
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                isr = new InputStreamReader(conn.getInputStream());
                br = new BufferedReader(isr);
                String temp;//from www .java2 s. c  om
                while ((temp = br.readLine()) != null) {
                    html.append(temp);
                }
            } catch (Exception e) {
                e.printStackTrace();
                return "";
            } finally {
                if (br != null) {
                    try {
                        br.close();
                    } catch (IOException ioe) {
                        ioe.printStackTrace();
                    }
                }
                if (isr != null) {
                    try {
                        isr.close();
                    } catch (IOException ioe) {
                        ioe.printStackTrace();
                    }
                }
            }
            return html.toString();
        } else {
            return "";
        }
    }
}

Related

  1. getFileSize(URL url)
  2. getFilesizeFromUrl(String urlString)
  3. getFromURL(String URL)
  4. getHTML(String pageURL, String encoding)
  5. getHtml(String url)
  6. getHTML(String urlToRead)
  7. getHTML(String urlToRead)
  8. getHttpResponse(HttpURLConnection conn, int expectedReturnCode)
  9. getHTTPResponse(String url)