Java URL Read getStringFromURL(String URLString)

Here you can find the source of getStringFromURL(String URLString)

Description

get String From URL

License

Creative Commons License

Declaration

public static String getStringFromURL(String URLString) 

Method Source Code

//package com.java2s;
//License from project: Creative Commons License 

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class Main {
    public static String getStringFromURL(String URLString) {
        try {// w  ww .jav a2 s.c  om
            URL URL = new URL(URLString);
            HttpURLConnection connection = (HttpURLConnection) URL
                    .openConnection();
            connection
                    .setRequestProperty(
                            "User-Agent",
                            "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
            connection.setDoInput(true);
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(connection.getInputStream()));
            return reader.readLine();
        } catch (Exception e) {
            return "";
        }
    }
}

Related

  1. getLastModified(HttpURLConnection connection)
  2. getRemoteFileLength(String url)
  3. getRemoteFileSize(URL url)
  4. getStreamByConnection(final HttpURLConnection con)
  5. getStringFromConnection(HttpURLConnection connection)
  6. getText(HttpURLConnection conn)
  7. getText(String url)
  8. getText(String url)
  9. getText(URL url)