/*
标题:复制网站内容
内容:
本程序将网站“www.baidu.com”首页的内容复制保存在文件test.html
中。写了如下代码,请完善之:
import java.net.*;
import java.io.*;
class DaSai{
public static void main(String[] args) throws Exception {
URL url=__________________________________;
BufferedReader in =_________________________________;
String inString;
File outfile=new File("test.html");
PrintWriter out=new PrintWriter(new FileWriter
(outfile));
while ((inString=in.readLine())!=null){
out.println(inString);
}
in.close();
out.close();
}
}
*/
1 import java.io.BufferedReader; 2 import java.io.File; 3 import java.io.FileWriter; 4 import java.io.InputStreamReader; 5 import java.io.PrintWriter; 6 import java.net.URL; 7 8 class pro07 { 9 public static void main(String[] args) throws Exception { 10 URL url=new URL("http://www.baidu.com"); 11 BufferedReader in =new BufferedReader(new InputStreamReader(url.openStream())); 12 String inString; 13 File outfile=new File("test.html"); 14 PrintWriter out=new PrintWriter(new FileWriter 15 16 (outfile)); 17 while ((inString=in.readLine())!=null){ 18 out.println(inString); 19 } 20 in.close(); 21 out.close(); 22 } 23 }
/*
这道题目,以前有学过,但没及时练习,都忘记了,现在也是边做边学,而且,发现写入的"test.html",打开之后出现了乱码,
*/