java通过文件路径下载文件
解决方法:
InputStream is=null;
OutputStream os=null;
try {
String fName = path.trim();
String file_name = fName.substring(fName.lastIndexOf("/")+1);
URL url=new URL(vo.getCall_record_path());
is=url.openStream();
response.addHeader("Content-Disposition", "attachment;filename="+file_name);
response.setContentType("application/octet-stream");
os= response.getOutputStream();
byte bf[]=new byte[1024];
int length=0;
while((length=is.read(bf, 0, 1024))!=-1){
os.write(bf, 0, length);
}
os.flush();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
is.close();
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}