java获取网页内容的代码如下:
import java.io.*; import java.net.URL; import java.net.URLConnection; /** * @param args */ public class GetHtmlContent { String urlSina="http://www.sina.com.cn"; public static void main(String[] args) throws IOException{ // TODO Auto-generated method stub test(); } public static void test()throws IOException{ URL url=new URL( urlSina); URLConnection conn = url.openConnection(); BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line = null; while ((line = reader.readLine()) != null) { System.out.println(line); } } }