Java URL Read readUrl(String url_str)

Here you can find the source of readUrl(String url_str)

Description

read Url

License

Open Source License

Declaration

public static String readUrl(String url_str) 

Method Source Code


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

import java.io.BufferedReader;

import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

public class Main {
    public static String readUrl(String url_str) {
        String text = "";
        try {/*w w  w. ja v a  2  s.  c  o  m*/
            URL url = new URL(url_str);
            URLConnection hc = url.openConnection();
            hc.setConnectTimeout(10000);
            hc.setConnectTimeout(10000);
            hc.setReadTimeout(10000);
            hc.setAllowUserInteraction(false);
            hc.setDoOutput(true);
            BufferedReader in = new BufferedReader(new InputStreamReader(hc.getInputStream(), "utf-8"));
            StringBuilder sb = new StringBuilder();
            String line;
            while ((line = in.readLine()) != null) {
                sb.append(line + "\n");
            }
            text = sb.toString();
            System.err.print("Get page " + url_str + "\n");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return text;
    }
}

Related

  1. readStringFromURL(String sourceURL)
  2. readUrl(final String strUrl)
  3. readUrl(final String url)
  4. readUrl(final String url_str)
  5. readURL(String path)
  6. readUrl(String urlString)
  7. readURL(URL url)
  8. readUrl(URL url)
  9. readUrl(URL url, String[]... headers)