Explorar o código

use 'try' with resources

sunyj %!s(int64=8) %!d(string=hai) anos
pai
achega
e9c16cb6b2

+ 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();
         }
 	}
 }