代码如下:
importjava.io.*;
importjava.net.MalformedURLException;
importjava.net.URL;
publicstaticvoidwriteFile(String strUrl,String fileName){
URL url =null;
try{
url =newURL(strUrl);
}catch(MalformedURLException e2) {
e2.printStackTrace();
}
InputStream is =null;
try{
is = url.openStream();
}catch(IOException e1) {
e1.printStackTrace();
}
OutputStream os =null;
File f =newFile("d:\\webimg\\");
f.mkdirs();
try{
os =newFileOutputStream("d:\\webimg\\"+fileName);
intbytesRead =0;
byte[] buffer =newbyte[8192];
while((bytesRead = is.read(buffer,0,8192))!=-1){
os.write(buffer,0,bytesRead);
}
}catch(FileNotFoundException e){
}catch(IOException e) {
e.printStackTrace();
}
}