Java URL Read readURL(String path)

Here you can find the source of readURL(String path)

Description

read URL

License

Open Source License

Declaration

public static String readURL(String path) throws MalformedURLException,
            IOException 

Method Source Code

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

import java.io.IOException;

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

public class Main {
    public static String readURL(String path) throws MalformedURLException,
            IOException {/*from   w  ww .  j av  a  2 s . c  o m*/
        URL url = new URL(path);
        URLConnection con = url.openConnection();
        Reader r = new InputStreamReader(con.getInputStream(), "UTF-8");
        StringBuilder buf = new StringBuilder();
        while (true) {
            int ch = r.read();
            if (ch < 0) {
                break;
            }
            buf.append((char) ch);
        }
        return buf.toString();
    }
}

Related

  1. readPage(String url)
  2. readStringFromURL(String sourceURL)
  3. readUrl(final String strUrl)
  4. readUrl(final String url)
  5. readUrl(final String url_str)
  6. readUrl(String url_str)
  7. readUrl(String urlString)
  8. readURL(URL url)
  9. readUrl(URL url)