public static void saveFp(String url, String savePath,String filename){
HttpGet httpGet = new HttpGet(url);
HttpClient httpClient=new DefaultHttpClient();
try {
HttpResponse response=httpClient.execute(httpGet);
HttpEntity entity = response.getEntity();
if (entity != null) {
byte[] byteArray = EntityUtils.toByteArray(entity);
//创建目录
File pathFile = new File(savePath);
if(!pathFile.exists()){
pathFile.mkdir();
}
//创建pdf文件
File pdfFile = new File(savePath+filename+".pdf");
if(!pdfFile.exists()){
pdfFile.createNewFile();
}
// //如果该文件所在目录不存在,则新创建该目录
// if(!file.getParentFile().exists()){
// File file2=new File(savePath);
// file2.mkdir();
// System.out.println(file2.mkdir());
// }
// if(!file.exists()){
// file.createNewFile();
// //创建目录
// //file.mkdir();
// System.out.println(file.createNewFile());
// } else {
// //file.delete();
// }
FileOutputStream fos = new FileOutputStream(pdfFile);
fos.write(byteArray);
fos.flush();
fos.close();
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
根据图片地址下载图片
最新推荐文章于 2024-07-04 20:55:58 发布