我写了一个下载二进制文件到本地的,调试过了,可以用
---------------------------------
/*
 * Created on 2004-10-28
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package http;import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
/**
 * @author NetSniffer
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class GetBin {

public static void saveBin(String strUrl) {
if(strUrl==null || strUrl.equals("")){
return;
}
try {
URL url = new URL(strUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
String binFile=url.getFile();
File binFileName=new File(binFile.substring(binFile.lastIndexOf('/')));
FileOutputStream binOutputStream=new FileOutputStream(".\\"+binFileName);
//得到图片的文件流
BufferedInputStream binInputStream = new BufferedInputStream(conn.getInputStream());

byte[] buffer=new byte[1024];
int len=0;
while ((len=binInputStream.read(buffer,0,1024))!= -1) {
binOutputStream.write(buffer,0,len);
}
binOutputStream.close();
binInputStream.close();
conn.disconnect();

} catch (Exception e) {
e.printStackTrace();
} }

public static void main(String[] args) {
saveBin("http://finance.dayoo.com/img/2004-10/13/xin_491417c21d2446658cfdd4fcc1f8e30c.jpg");
System.out.println("Down!!");
}
}=====================================
运行完后,当前目录下就可以看到 xin_491417c21d2446658cfdd4fcc1f8e30c.jpg 

解决方案 »

  1.   

    测试可以通过,万分感想^_^
    只是不明白这里,希望可以帮忙解答一下^_^
     byte[] buffer = new byte[1024];//这里的1024的大小是指什么的限制,会不会限制下载东西的大小?
      

  2.   

    buffer 是一个固定长度的缓冲区【字节数组】,不断地从HTTP输入流中读取1024个字节到buffer中,同时把读出的【字节数组】写入到文件输出流中,直到HTTP流末尾。