package com.linxinxin.tools;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
public class CrawlerUtil {
public static void main(String[] a){
try {
URL url=new URL("http://www.baidu.com");
BufferedReader reader=new BufferedReader(new InputStreamReader(url.openStream()));
BufferedWriter writer=new BufferedWriter(new FileWriter("index.html"));
String line;
while((line=reader.readLine())!=null){
System.out.println(line);
writer.write(line);
writer.newLine();
}
reader.close();
writer.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}