Java URL Read readUrlToString(String urlString)

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

Description

read Url To String

License

Open Source License

Declaration

public static String readUrlToString(String urlString) 

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 readUrlToString(String urlString) {
        try {/*from   w w w .j  av  a 2 s  .  c  o m*/
            URL website = new URL(urlString);
            URLConnection connection = website.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));

            StringBuilder response = new StringBuilder();
            String inputLine;

            while ((inputLine = in.readLine()) != null)
                response.append(inputLine);
            in.close();
            return response.toString();

        } catch (Exception e) {
            //         Util.debug("Util.readUrlToString() parse error: "+urlString, "Util.readUrlToString()");
            return null;
        }
    }
}

Related

  1. readUrl(URL url)
  2. readUrl(URL url, String[]... headers)
  3. readURL(URLConnection connection, String charset)
  4. readUrlContent(URLConnection connection)
  5. readURLToString(String url)
  6. readVersion(URLConnection connection)
  7. retrieve(URL url)
  8. retrieveResponseMessage(HttpURLConnection connection)