deason 5 年之前
父节点
当前提交
557c5d78dc

+ 6 - 13
examcloud-core-questions-base/src/main/java/cn/com/qmth/examcloud/core/questions/base/FileDisposeUtil.java

@@ -57,23 +57,19 @@ public class FileDisposeUtil {
                 if (fileOutputStream != null) {
                     fileOutputStream.flush();
                     fileOutputStream.close();
-                    fileOutputStream = null;
                 }
                 if (dataOutputStream != null) {
                     dataOutputStream.flush();
                     dataOutputStream.close();
-                    dataOutputStream = null;
                 }
                 if (dataInputStream != null) {
                     dataInputStream.close();
-                    dataInputStream = null;
                 }
             } catch (IOException e) {
                 logger.error(e.getMessage(), e);
             }
             if (connection != null) {
                 connection.disconnect();
-                connection = null;
             }
         }
     }
@@ -88,25 +84,26 @@ public class FileDisposeUtil {
     public static void downloadFile(String filename, String fullFilePath, HttpServletResponse response) {
         InputStream in = null;
         OutputStream out = null;
+
         try {
             //设置编码
             response.setCharacterEncoding("UTF-8");
+
             //设置文件MIME类型
             response.setContentType(getContentType(filename));
+
             //设置Content-Disposition,名称强制为UTF-8
-            //String fileEncode = System.getProperty("file.encoding");
-            //response.setHeader("Content-Disposition", "attachment;filename="+new String(filename.getBytes(fileEncode),"UTF-8"));
-            //response.setHeader("Content-Disposition", "attachment;filename="+URLEncoder.encode(filename,"UTF-8"));
             response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8")
                     .replace("%28", "(")
                     .replace("%29", ")"));
+
             // 设置强制下载不打开
             response.setContentType("application/octet-stream;charset=utf-8");
+
             //读取目标文件,通过response将目标文件写到客户端
-            //获取目标文件的绝对路径
-            //读取文件
             in = new FileInputStream(fullFilePath);
             out = response.getOutputStream();
+
             //写文件
             byte[] buffer = new byte[4096];
             int count = 0;
@@ -124,18 +121,14 @@ public class FileDisposeUtil {
             try {
                 if (null != out) {
                     out.close();
-                    out = null;
                 }
                 if (null != in) {
                     in.close();
-                    in = null;
                 }
             } catch (IOException e) {
                 logger.error(e.getMessage(), e);
-                throw new RuntimeException(e);
             }
         }
-
     }
 
     /**