tanxuedan

下载文件

/**

*图片下载

*url 图片地址

*path下载的路径(存放位置)

*index多图下载图片下标

*postfix 图片后缀

*/

private File downLoadImage(String url, String path, int index ,String postfix) throws Exception {
URL ul = new URL(url);
URLConnection uc = ul.openConnection();
File file = new File(path, "f" + index + postfix);
FileOutputStream fos = new FileOutputStream(file);
IOUtils.copy(uc.getInputStream(), fos);
IOUtils.close(uc);
IOUtils.closeQuietly(fos);
return file;
}

 

/**

*文件下载

*path下载的路径(存放位置)

*file  下载的文件

*/

private File downLoadFile(path,file) throws Exception {
File paramFile = new File(path, file);
OutputStreamWriter write = new OutputStreamWriter(new FileOutputStream(paramFile),"utf-8");
BufferedWriter bw = new BufferedWriter(write);
bw.write(mapper.writeValueAsString(command));
bw.flush();
bw.close();
return paramFile;
}

posted on 2016-11-25 10:55  TaraSherridan  阅读(75)  评论(0编辑  收藏  举报

导航