Java抓取网页内容三种方式.docxVIP

  • 5
  • 0
  • 约3.62千字
  • 约 5页
  • 2017-11-17 发布于河南
  • 举报
Java抓取网页内容三种方式

java抓取网页内容三种方式2011-12-05 11:23一、GetURL.javaimport java.io.*;import .*; public class GetURL {public static void main(String[] args) {InputStream in = null; OutputStream out = null;try {// 检查命令行参数if ((args.length != 1) (args.length != 2)) throw new IllegalArgumentException(Wrong number of args);URL url = new URL(args[0]); //创建 URLin = url.openStream(); // 打开到这个URL的流if (args.length == 2) // 创建一个适当的输出流out = new FileOutputStream(args[1]);else out = System.out;// 复制字节到输出流byte[] buffer = new byte[4096];int bytes_read;while((bytes_read = in.read(buffer)) != -1)out.write(buffer, 0, bytes_read);}catch (

文档评论(0)

1亿VIP精品文档

相关文档