Java URL Read getTextFromURL(final String url)

Here you can find the source of getTextFromURL(final String url)

Description

get Text From URL

License

Open Source License

Declaration

public static String getTextFromURL(final String url) 

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.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class Main {
    public static String getTextFromURL(final String url) {
        StringBuilder result = new StringBuilder();
        try {/*from w  w w  . j  a  v a  2  s.c om*/
            final URL website = new URL(url);
            final URLConnection connection = website.openConnection();
            final BufferedReader in = new BufferedReader(
                    new InputStreamReader(connection.getInputStream()));

            String inputLine;

            while ((inputLine = in.readLine()) != null)
                result.append(inputLine);

            in.close();

        } catch (MalformedURLException e) {
            e.printStackTrace(); //TODO FCRES: Autogenerated, modify
        } catch (IOException e) {
            e.printStackTrace(); //TODO FCRES: Autogenerated, modify
        }

        return result.toString();
    }
}

Related

  1. getStringFromURL(String URLString)
  2. getText(HttpURLConnection conn)
  3. getText(String url)
  4. getText(String url)
  5. getText(URL url)
  6. getTextFromURL(URL url)
  7. getTextFromURL(URL url)
  8. getURL(final URL url)
  9. getURL(String url)