// 根据 远程地址 下载文件到指定位置
public String downLoadFromUrl(String fileUrl,String fileName,String savePath) throws IOException{
//获取连接
URL url=new URL(fileUrl);
HttpURLConnection connection=(HttpURLConnection)url.openConnection();
connection.setConnectTimeout(3*1000);
//设置请求头
connection.setRequestProperty("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36");
//获取输入流
InputStream in=connection.getInputStream();File saveDir=new File(savePath);
if(!saveDir.exists()){
saveDir.mkdirs();
}
File file=new File(savePath+fileName);OutputStream out=new FileOutputStream(file);
byte[] bytes=new byte[1024];
int len=0;
while((len=in.read(bytes))!=-1){
out.write(bytes,0,len);
}
out.close();
in.close();logger.info("签章后的合同文件下载成功!--> filePath:"+file.getPath());
return file.getPath();
}