内容目录
/**
* 创建一个临时文件
* @param url 远端文件Url
* @return File
*/
private File getFile(String url) {
//对本地文件命名
String fileName = url.substring(url.lastIndexOf("."), url.length());
File file = null;
URL urlfile;
try {
// 创建一个临时路径
file = File.createTempFile("file", fileName);
//下载
urlfile = new URL(url);
try (InputStream inStream = urlfile.openStream();
OutputStream os = new FileOutputStream(file);) {
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = inStream.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytesRead);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return file;
}