一段简单的用URL类访问网上资源代码 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; public class GetHtml { public static void main(String[] args) throws IOException { if (args.length != 1){ System.out.println("Usage:java Web url"); return; } URL url = new URL(args[0]);//根据命令行参数创建一个URL对象 BufferedReader bd = new BufferedReader(new InputStreamReader(url.openStream()));//openStream方法的返回值为建立连接了的输入流 String line; while ((line = bd.readLine()) != null) System.out.println(line);//逐行打印html代码 bd.close(); } }