Here you can find the source of readURL(URL url)
Parameter | Description |
---|---|
url | also known as web address, particularly when used with HTTP |
Parameter | Description |
---|---|
MalformedURLException | an exception |
IOException | an exception |
public static String readURL(URL url) throws MalformedURLException, IOException
//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; } }