springboot下载问题,我写了一个下载方法,如下:
public static String downloadFile(HttpServletResponse response, String fileName, String filePath) {
File path =null;
response.addHeader("Access-Contro1-A11ow-0rigin","*");
response.setHeader("content-type","application/octet-stream");
response.setContentType("application/octet-stream");
try {
response.setHeader("Content-Disposition","attachment;filename=" + java.net.URLEncoder.encode(fileName,"UTF-8"));
} catch (UnsupportedEncodingException e){
e.printStackTrace();
}
byte[] buff =new byte[1024];
BufferedInputStream bis =null;
OutputStream os =null;
try {
path =new File(filePath);
os = response.getOutputStream();
bis =new BufferedInputStream(new FileInputStream(path));
int i = bis.read(buff);
while (i != -1) {
os.write(buff,0, buff.length);
os.flush();
i = bis.read(buff);
}
} catch (FileNotFoundException e){
e.printStackTrace();
System.out.println("系统找不到指定文件");
} catch (IOException e){
e.printStackTrace();
} finally {
if (bis !=null) {
try {
bis.close();
}catch (IOException e) {
e.printStackTrace();
}
}
}
return "success";
}
但是当我访问这个接口的时候发现下载下来的apk无法进行安装,会提示解析包错误,但下载图片啥的又正常,我想知道我有什么地方搞错了?