Here you can find the source of readStringFromUrl(URL url)
Parameter | Description |
---|---|
url | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static String readStringFromUrl(URL url) throws IOException
//package com.java2s; import java.io.*; import java.net.URL; public class Main { /**//from www.j a va2s .c o m * Reads content from specified URL * @param url * @throws IOException * @return Read content as string. */ public static String readStringFromUrl(URL url) throws IOException { StringBuffer buffer = new StringBuffer(); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); int ch; while ((ch = in.read()) != -1) { buffer.append((char) ch); } in.close(); return buffer.toString(); } }