瀏覽代碼

use 'try' with resources

sunyj 8 年之前
父節點
當前提交
e9c16cb6b2
共有 1 個文件被更改,包括 1 次插入4 次删除
  1. 1 4
      report/src/main/java/com/uas/report/controller/PdfController.java

+ 1 - 4
report/src/main/java/com/uas/report/controller/PdfController.java

@@ -249,9 +249,8 @@ public class PdfController {
 		if(!file.getName().toLowerCase().endsWith(".pdf")){
 		if(!file.getName().toLowerCase().endsWith(".pdf")){
 			throw new IOException("并非 pdf 文件:" + p);
 			throw new IOException("并非 pdf 文件:" + p);
 		}
 		}
-        FileInputStream fis = new FileInputStream(file);
 
 
-        try {
+        try (FileInputStream fis = new FileInputStream(file)) {
             response.setHeader("Content-Length", file.length() + "");
             response.setHeader("Content-Length", file.length() + "");
             response.setContentType("application/pdf");
             response.setContentType("application/pdf");
 
 
@@ -266,8 +265,6 @@ public class PdfController {
             } catch (IOException e) {
             } catch (IOException e) {
                 logger.error(e.getMessage());
                 logger.error(e.getMessage());
             }
             }
-        } finally {
-            fis.close();
         }
         }
 	}
 	}
 }
 }