Here you can find the source of retrieve(URL url)
public static String retrieve(URL url) throws IOException
//package com.java2s; /**************************************************************************** * Copyright (c) 2010 Giorgio Sironi. 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 ****************************************************************************/ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; public class Main { public static String retrieve(URL url) throws IOException { HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); InputStream is = conn.getInputStream(); ByteArrayOutputStream output = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; for (int bytesRead = 0; (bytesRead = is.read(buffer)) != -1;) { output.write(buffer, 0, bytesRead); }//from ww w.j ava 2s .c om return output.toString(); } }