DownLoad文件

response.setContentType("application/octet-stream");

//Content-Disposition : 保存文件時設置的頭信息
//Windows-31J : windows的標準字符集
//ISO-8859-1  :  編碼格式
//爲了防止文件名中出現中文,發生亂碼
response.setHeader("Content-Disposition", 
                   "attachment; filename=" + new String(fileName.getBytes("Windows-31J"), "ISO-8859-1"));

InputStream  in  = new FileInputStream(filePath);
OutputStream out = response.getOutputStream();
byte[] buff = new byte[1024];
int len = 0;
while ((len = in.read(buff, 0, buff.length)) != -1) {
    out.write(buff, 0, len);
}

in.close();
out.close();
相關文章
相關標籤/搜索