Browse Source

Use try-with-resources when loading properties

Mathias Landhäußer 11 years ago
parent
commit
5cfe597906
1 changed files with 19 additions and 21 deletions
  1. 19 21
      jplag.utils/src/main/java/jplagUtils/PropertiesLoader.java

+ 19 - 21
jplag.utils/src/main/java/jplagUtils/PropertiesLoader.java

@@ -1,21 +1,19 @@
-package jplagUtils;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-
-public class PropertiesLoader {
-	public static Properties loadProps(String resourceName) {
-		InputStream in = PropertiesLoader.class.getClassLoader().getResourceAsStream(resourceName);
-		Properties props = new Properties();
-		if (in != null) {
-			try {
-				props.load(in);
-				in.close();
-			} catch (IOException e) {
-				e.printStackTrace();
-			}
-		}
-		return props;
-	}
-}
+package jplagUtils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+public class PropertiesLoader {
+	public static Properties loadProps(String resourceName) {
+		Properties props = new Properties();
+		try (InputStream in = PropertiesLoader.class.getClassLoader()
+				.getResourceAsStream(resourceName);) {
+			props.load(in);
+			in.close();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		return props;
+	}
+}