code: public static String readURLToString(URL u, String encoding) throws IOException {
  		for (int i = 0; i < 30; ++i) {
  			URLConnection conn = u.openConnection();
  
  			// handle HTTP URLs
  			if (conn instanceof HttpURLConnection) {
  				HttpURLConnection hconn = (HttpURLConnection)conn;
  
  				// set timeouts
  				hconn.setConnectTimeout(15000);
  				hconn.setReadTimeout(15000);
  
  				// handle redirects
  				switch (hconn.getResponseCode()) {
  				case HttpURLConnection.HTTP_MOVED_PERM:
  				case HttpURLConnection.HTTP_MOVED_TEMP:
  					String location = hconn.getHeaderField("Location");
  					u = new URL(u, location);
  					continue;
  				}
  			}
  
  			return readStreamToString(conn.getInputStream(), encoding);
  		}
  
  		throw new IOException("Too many HTTP redirects");
  	}
docs: Reads a string from a URL
  @param u the URL
  @param encoding the character encoding
  @return the string
  @throws IOException if the URL contents could not be read