Advertisement
Guest User

Untitled

a guest
Sep 30th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.48 KB | None | 0 0
  1. public void ex1(View w){
  2.         String ans = "";
  3.         try{
  4.             URL url = new URL("http://www.example.com");
  5.             URLConnection con =(URLConnection) url.openConnection();
  6.             con.connect();
  7.             InputStream is = con.getInputStream();
  8.             int r = is.read();
  9.             while(r != -1){
  10.                 ans += (char) r;
  11.                 r = is.read();
  12.             }
  13.            
  14.         }
  15.         catch(Exception e){ ans += "Error";}
  16.         TextView s = (TextView) findViewById(R.id.textView1);
  17.         s.setText(ans);
  18.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement