public void writeDocument(String url,String filename) throws IOException{
FileOutputStream fos = null;
BufferedInputStream bis = null;
HttpURLConnection httpUrl = null;
int size = 0;
myurl = new URL(url);
httpUrl = (HttpURLConnection) myurl.openConnection();
fos = new FileOutputStream(filename);
System.out.println("正在获取链接【"+url+"】的内容...");
System.out.println("正在保存为文件【"+filename+"】。");
while((size = bis.read(buf))!=-1){
fos.write(buf,0,size);
}
fos.close();
bis.close();
httpUrl.disconnect();
System.out.println("文件【"+filename+"】下载结束。");
}
FileOutputStream fos = null;
BufferedInputStream bis = null;
HttpURLConnection httpUrl = null;
URL myurl = null;
//BUFFER_SIZE:缓冲区大小
byte[] buf = new byte[this.BUFFER_SIZE];int size = 0;
myurl = new URL(url);
httpUrl = (HttpURLConnection) myurl.openConnection();
httpUrl.connect();
//获得URL链接的InputStream流
bis = new BufferedInputStream(httpUrl.getInputStream());fos = new FileOutputStream(filename);
System.out.println("正在获取链接【"+url+"】的内容...");
System.out.println("正在保存为文件【"+filename+"】。");
while((size = bis.read(buf))!=-1){
fos.write(buf,0,size);
}
fos.close();
bis.close();
httpUrl.disconnect();
System.out.println("文件【"+filename+"】下载结束。");
}