Java Read Content From Intenet HTML

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;


public class ReadInternetHtmlTest {

 /**
  * @param args
  * @throws Exception
  */
 public static void main(String[] args) throws Exception {
  // TODO Auto-generated method stub
  URL url = new URL("http://localhost:8080");
  URLConnection conn = url.openConnection();
  //File file = new File("http://www.baidu.com");
  try {
   BufferedReader buffer = new BufferedReader(new InputStreamReader(conn.getInputStream()));
   String line = buffer.readLine();
   while(null != line){
    System.out.println(line);;
    line = buffer.readLine();
   }
   buffer.close();
   
  } catch (FileNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }

}

你可能感兴趣的:(content)