Posted By

mscribellito on 04/14/11


Tagged


Versions (?)

Read File From URL


 / Published in: Java
 

  1. import java.net.*;
  2. import java.io.*;
  3.  
  4. public class URLReader {
  5.  
  6. private String url;
  7.  
  8. public URLReader(String url) {
  9.  
  10. this.url = url;
  11.  
  12. }
  13.  
  14. public String read() throws Exception {
  15.  
  16.  
  17. URL u = new URL(this.url);
  18.  
  19. u.openStream()
  20. )
  21. );
  22.  
  23. String line;
  24.  
  25. while ((line = in.readLine()) != null) {
  26.  
  27. sb.append(line);
  28.  
  29. }
  30.  
  31. return sb.toString();
  32.  
  33. }
  34.  
  35. public static void main(String[] args) {
  36.  
  37. URLReader u = new URLReader("http://mscribellito.com");
  38.  
  39. try {
  40.  
  41. System.out.println(u.read());
  42.  
  43. } catch (Exception e) {
  44.  
  45. System.out.println(e.getMessage());
  46.  
  47. }
  48.  
  49. }
  50.  
  51. }

Report this snippet  

You need to login to post a comment.