根据URL获取文件
public static File getFileByHttpURL(String path){
String newUrl = path.split("[?]")[0];
String[] suffix = newUrl.split("/");
String fileName = suffix[suffix.length - 1];
File file = null;
InputStream inputStream = null;
OutputStream outputStream = null;
try{
file = File.createTempFile("report",fileName);
URL urlFile = new URL(newUrl);
inputStream = urlFile.openStream();
outputStream = new FileOutputStream(file);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead=inputStream.read(buffer,0,8192))!=-1) {
outputStream.write(buffer, 0, bytesRead);
}
}catch (Exception e) {
e.printStackTrace();
}finally {
try {
if (null != outputStream) {
outputStream.close();
}
if (null != inputStream) {
inputStream.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return file;
}