package com.netprogramming.url;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
/**
* 功能:我想下载某网站的网页的内容
*
*/
public class TestURL2 {
public static void main(String[] args) throws UnsupportedEncodingException, IOException {
//www.baidu.com
URL url=new URL("http://www.sina.com.cn");
//怎样把文件下载下来
// InputStream is=url.openStream();
//读出来
BufferedReader br=new BufferedReader(new InputStreamReader(url.openStream(), "utf-8"));
//打印流输出
PrintWriter pw=new PrintWriter("e:"+File.separator+"test"+File.separator+"xinlang.html","UTF-8");
// PrintStream ps=new PrintStream(new FileOutputStream("e:"+File.separator+"test"+File.separator+"xinlang.html"));
//读出并输出
String str=br.readLine();
while(str!=null){
// System.out.println(str);
pw.write(str);
pw.println();
// ps.println(str);
str=br.readLine();
}
br.close();
pw.close();
// ps.close();
}
}
下载某网站的网页的内容
最新推荐文章于 2024-07-29 06:30:57 发布
894

被折叠的 条评论
为什么被折叠?



