Created
May 17, 2016 13:20
-
-
Save andrea-ale-sbarra/b3185be8c7b8c82dec55a25d79918895 to your computer and use it in GitHub Desktop.
read .properties from classpath
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Properties prop = new Properties(); | |
InputStream input = null; | |
try { | |
String filename = "config.properties"; | |
input = this.getClass().getClassLoader().getResourceAsStream(filename); | |
if (input == null) { | |
System.out.println("Sorry, unable to find " + filename); | |
throw new java.lang.UnsupportedOperationException("Some errors occurred, please try again later."); | |
} | |
// load a properties file from class path, inside static method | |
prop.load(input); | |
// get the property value and print it out | |
System.out.println(prop.getProperty("filsystem.root")); | |
} catch (IOException ex) { | |
throw new java.lang.UnsupportedOperationException("Some errors occurred, please try again later."); | |
} finally { | |
if (input != null) { | |
try { | |
input.close(); | |
} catch (IOException e) { | |
throw new java.lang.UnsupportedOperationException("Some errors occurred, please try again later."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment