/* 
The method "openStream()" is the responsible of 
opening a connection with the URL and returning a result to read.
*/

private String readURL(URL url) throws IOException {
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   InputStream is = null;
   try {
      is = url.openStream();
   } catch (Exception e) {
      e.printStackTrace();
   }
   int r;
   while ((r = is.read()) != -1) {
      baos.write(r);
   }
   return new String(baos.toByteArray());
}