下载文件名乱码

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;

你可能感兴趣的:(乱码,文件名)