java文件下载工具java下载文件0kb

java文件下载工具java下载文件0kb

描述

java文件下载工具java下载文件0kb

你程序中打出来看下里面内容是不为空

<%

response.setContentType(fileminitype);

response.setHeader("Location",filename);

response.setHeader("Cache-Control", "max-age=" + cacheTime);

response.setHeader("Content-Disposition", "attachment; filename=" + filename); //filename应该是编码后的(utf-8)

response.setContentLength(filelength);

OutputStream outputStream = response.getOutputStream();

InputStream inputStream = new FileInputStream(filepath);

java文件下载工具图片1

byte[] buffer = new byte[1024];

int i = -1;

while ((i = inputStream.read(buffer)) != -1) {

outputStream.write(buffer, 0, i);

}

java文件下载工具图片2

outputStream.flush();

java文件下载工具图片3

outputStream.close();

inputStream.close();

outputStream = null;

%>



留言