package com.webkfa.test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class Test {
public static void main(String[] args) throws IOException{
StringBuffer htmlbf = getHtmlContext("http://www.webkfa.com");
System.out.println(htmlbf.toString());
}
/**
* 得到http内容
* @param hpath
* @return
* @throws IOException
*/
public static StringBuffer getHtmlContext(String hpath) throws IOException{
StringBuffer bf=new StringBuffer();
HttpURLConnection httpUrl = null;
URL uobj = new URL(hpath);
httpUrl = (HttpURLConnection) uobj.openConnection();
httpUrl.connect();
InputStream is = httpUrl.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line = null;
while( (line = br.readLine()) != null ){
bf.append(line+"\r\n");
}
br.close();
isr.close();
is.close();
return bf;
}
}