Browse Source

use 'try' with resources

sunyj 8 years ago
parent
commit
e9c16cb6b2
1 changed files with 1 additions and 4 deletions
  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")){
 			throw new IOException("并非 pdf 文件:" + p);
 		}
-        FileInputStream fis = new FileInputStream(file);
 
-        try {
+        try (FileInputStream fis = new FileInputStream(file)) {
             response.setHeader("Content-Length", file.length() + "");
             response.setContentType("application/pdf");
 
@@ -266,8 +265,6 @@ public class PdfController {
             } catch (IOException e) {
                 logger.error(e.getMessage());
             }
-        } finally {
-            fis.close();
         }
 	}
 }