자바 웹 페이지 내용 가 져 오기

1032 단어
package DC.Utility;


import java.io.BufferedReader;

import java.io.InputStreamReader;


public class GetWebContent {

	 public static String getWebCon(String domain) {

		 // System.out.println("      ...("+domain+")");

		 StringBuffer sb = new StringBuffer();

		 try {

			 java.net.URL url = new java.net.URL(domain);

			 BufferedReader in = new BufferedReader(new InputStreamReader(url

					 .openStream()));

			 String line;

			 while ((line = in.readLine()) != null) {

				 sb.append(line);

			 }

			 System.out.println(sb.toString());

			 in.close();

		 } catch (Exception e) { // Report any errors that arise

			 sb.append(e.toString());

			 System.err.println(e);

			 System.err

					 .println("Usage:   java   HttpClient   <URL>   [<filename>]");

		 }

		 return sb.toString();

	 }


	 public static void main(String[] args) {

		 getWebCon("http://www.pczpg.com/html/bianchengkaifa/Java/20090711/9706.html");

	 }

}

좋은 웹페이지 즐겨찾기