获取网页html代码

获取网页html代码类
import java.net.*;
import java.io.*;

public class WebCode {
	public static void main(String args[]) throws Exception{

	    URL url=new URL("http://www.chinadaily.com.cn/enewsletter/headlinenews.html ");
	    URLConnection connection=url.openConnection();
	    InputStream in=connection.getInputStream();
	    ByteArrayOutputStream buffer=new ByteArrayOutputStream();
	    byte[] buff=new byte[1024];
	    int len=-1;
	    while((len=in.read(buff))!=-1){
	      buffer.write(buff,0,len);
	    }
	    System.out.println(new String(buffer.toByteArray()));
	}

}

你可能感兴趣的:(java,html,.net)