下载文件名乱码

来源:互联网 发布:qq强制视频软件 编辑:程序博客网 时间:2024/06/05 14:34
File downFile=new File(path,fileName);     response.setContentType("binary/octet-stream");//解决文件名乱码,IE默认是gb2312,不能用UTF-8。 response.setHeader("Content-Disposition", "attachment; filename=" + new String(downFile.getName().getBytes("gb2312"),"iso8859-1"));         ServletOutputStream servletOutputStream = response.getOutputStream();             InputStream is=new FileInputStream(downFile);            byte[] bytes = new byte[1024];   while (true) {    int chunk = is.read(bytes);    if (chunk == -1) {     break;    }    servletOutputStream.write(bytes, 0, chunk);   }   is.close();   is = null;
0 0