网面抓取(流机制)

/*
 * 实现网页抓取http://www.qq.com
 * 技术:导入URl地址,从URl地址中获取字节流,Reader使字节流转成字符流,用行读取方法读字符,把所有的字符串连接,用OutputStream的Write方法写入到文件中
 */

package tengxun;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;

public class Tengxun {
 
 public static void main(String[] args)
 {
  try
  {
   File f = new File("E:\\MyEclipse6.5\\workspace\\PageGet\\src\\tengxun\\qq.html");
   URL url = new URL("http://www.qq.com");
   InputStream is = url.openStream();
   BufferedReader br= new BufferedReader(new InputStreamReader(is));
   String s = br.readLine();
   String last = "";
   FileOutputStream fo = new FileOutputStream(f);
   while(s != null)
   {
    last = last + s;
    s =  br.readLine();
   }
   byte[] b = last.getBytes();
   fo.write(b, 0, b.length); 
   System.out.println("succeeful!!!");
   fo.close();
  }
  catch(Exception e)
  {
   System.out.print(e);
  }
 }
}

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