Here you can find the source of readContents(URL url)
public static String readContents(URL url) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2010-2012 Nikita Zhiltsov. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html//ww w . java 2s . co m * * Contributors: * Nikita Zhiltsov - initial API and implementation * Azat Khasanshin - implementation ******************************************************************************/ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; public class Main { public static String readContents(URL url) throws IOException { InputStream inputStream = url.openStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); StringBuffer contentsBuffer = new StringBuffer(); try { String value; while ((value = reader.readLine()) != null) { contentsBuffer.append(value); contentsBuffer.append("\n"); } } finally { reader.close(); inputStream.close(); } return contentsBuffer.toString(); } }