Tuesday, November 11, 2008

Accessing resources from Java Class

Here is a simple code snippet that can be used to get properties file from a java program.
Properties config = new Properties(); 
try {
config.load(new FileInputStream(new File(URLDecoder.decode(getClass().getClassLoader().getResource(CONFIG_FILE_NAME).getFile(), "UTF-8"))));
} catch (Exception e1) {
throw new RuntimeException(e1);

This, snippet has never let me down till now in getting a properties file.

No comments:

Post a Comment