java处理下载的逻辑
public String dowmloadElectronicCertificate(HttpServletResponse response,String ywh) {
File filePah = tificateService.dowmloadtificate(ywh);
RequestElectronicCertificateUtil.download(filePah,response);
}
public static HttpServletResponse download(File file, HttpServletResponse response) {
try {
// path是指欲下载的文件的路径。
//File file = new File(path);
// 取得文件名。
String filename = file.getName();
logger.info("下载文件名为======"+filename);
// 取得文件的后缀名。
String ext = filename.substring(filename.lastIndexOf(".") + 1).toUpperCase();
// 以流的形式下载文件。
InputStream fis = new BufferedInputStream(new FileInputStream(file));
byte[] buffer = new byte[fis.available()];
fis.read(buffer);
fis.close();