文件下载问题

File file = new File(path);
InputStream is = new FileInputStream(file);
OutputStream os = response.getOutputStream();// get the
// outputstream
BufferedInputStream bis = new BufferedInputStream(is);
BufferedOutputStream bos = new BufferedOutputStream(os);
fileName = java.net.URLEncoder.encode(fileName, "UTF-8");
// encoding for Chinese
fileName = new String(fileName.getBytes("UTF-8"), "gb2312");
response.reset();
response.setCharacterEncoding("UTF-8");
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition", 
                                 "attachment;filename="+fileName);
int bytesRead = 0;
byte[] buffer = new byte[1024 * 8];
while ((bytesRead = bis.read(buffer)) != -1) {
	bos.write(buffer, 0, bytesRead);// buffer read
}
bos.flush();
bis.close();
bos.close();
is.close();
os.close();
 

你可能感兴趣的:(文件下载)