来者有分,下载文件我这么做对吗?
import java.io.*;
import java.net.*;
.....
try{
URL url=new URL ("http://。。。。。/zip.exe");
HttpURLConnection httpCon=(HttpURLConnection)url.openConnection();
httpCon.setRequestProperty ("User-Agent","NetFox");
httpCon.setRequestProperty ("RANGE","bytes=0");
InputStream input=httpCon.getInputStream ();
RandomAccessFile file=new RandomAccessFile ("c:\\zip.exe","wr");
file.seek (0);
byte[] b=new byte [1024];
int count;
while((count=input.read (b,0,1024))>0)
{file.write (b,0,count);}
System.out.println ("下载完毕");
}catch (IOException w){System.out.println ("io");}
catch (Exception w){System.out.println ("other");}}