@RequestMapping("/download.xls")
public void testDownload1(HttpServletResponse res) {
String fileName = "1.xls";
res.setHeader("content-disposition", "attachment;filename="+fileName);
res.setHeader("content-type", "application/vnd.android.package-archive");
byte[] buff = new byte[1024];
BufferedInputStream bis = null;
OutputStream os = null;
File file = new File(Constant.XLS_DOWNLOAD_PATH+ fileName);
long length = file.length();
System.out.println(length);
res.setHeader("Content-Length",String.valueOf(length));
try {
os = res.getOutputStream();
bis = new BufferedInputStream(new FileInputStream(file));
int i = bis.read(buff);
while (i != -1) {
os.write(buff, 0, buff.length);
os.flush();
i = bis.read(buff);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (bis != null) {
try {
bis.close();
} catch (IOException e) {
e.printStackTrace();
}
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余1页未读,立即下载