Posted By

LucasRinaldi on 08/15/12


Tagged


Versions (?)

Read URL connection result


 / Published in: Java
 

The method "openStream();" is that opens a connection with that URL and returns a result to read.

  1. private String readURL(URL url) throws IOException {
  2. InputStream is = null;
  3. try {
  4. is = url.openStream();
  5. } catch (Exception e) {
  6. e.printStackTrace();
  7. }
  8. int r;
  9. while ((r = is.read()) != -1) {
  10. baos.write(r);
  11. }
  12. return new String(baos.toByteArray());
  13. }

Report this snippet  

You need to login to post a comment.