62,614
社区成员
发帖
与我相关
我的任务
分享
import java.io.*;
import java.util.*;
import java.net.*;
import java.sql.*;
public class Test
{
public static void main(String[] args) throws Exception
{
URL u = new URL("网址");
HttpURLConnection con = (HttpURLConnection)u.openConnection();
con.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C)");
InputStream is = con.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("test.html"));
byte[] arr = new byte[512];
int temp;
while((temp = bis.read(arr, 0, 512)) != -1)
{
bos.write(arr, 0, temp);
}
bos.flush();
bos.close();
bis.close();
}
}
http://www.javaeye.com