Here you can find the source of readFromURL(URL url)
public static String readFromURL(URL url) throws IOException, UnsupportedEncodingException
//package com.java2s; /******************************************************************************* * Copyright (c) 2009, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors://w ww. j a va 2 s . co m * IBM Corporation - initial API and implementation *******************************************************************************/ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.net.URL; public class Main { public static String readFromURL(URL url) throws IOException, UnsupportedEncodingException { InputStream is = url.openStream(); InputStreamReader inputStreamReader = new InputStreamReader(is, "UTF-8"); StringBuffer buffer = new StringBuffer(); char[] cbuf = new char[256]; int len; do { len = inputStreamReader.read(cbuf); if (len > 0) { buffer.append(cbuf, 0, len); } } while (len >= 0); inputStreamReader.close(); return buffer.toString(); } }