Java URL Load readURL(URL url)

Here you can find the source of readURL(URL url)

Description

Read from a URL into a string

License

Open Source License

Parameter

Parameter Description
url also known as web address, particularly when used with HTTP

Exception

Parameter Description
MalformedURLException an exception
IOException an exception

Declaration

public static String readURL(URL url) throws MalformedURLException, IOException 

Method Source Code


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

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

public class Main {
    /**//from www  .  j a v a  2  s .c  o  m
     * Read from a URL into a string
     *
     * @param url also known as web address, particularly when used with HTTP
     * @return
     * @throws MalformedURLException
     * @throws IOException
     */
    public static String readURL(URL url) throws MalformedURLException, IOException {
        String str = "";
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String inputLine;
        while ((inputLine = in.readLine()) != null)
            str += inputLine + "\n";
        in.close();
        return str;
    }
}

Related

  1. readURL(String url)
  2. readURL(String url, String charsetName)
  3. ReadURL(String URLAddress)
  4. readUrl(String urlString)
  5. readURL(URL fileURL)
  6. readUrl(URL url)
  7. readURL(URL url)
  8. readURL(URL url)
  9. readURL(URL url)