View Javadoc

1   package org.paneris.util;
2   
3   import java.util.Properties;
4   import java.io.IOException;
5   import java.io.FileNotFoundException;
6   import java.io.InputStream;
7   
8   public class PropertiesUtils {
9   
10    public static Properties fromResource(Class clazz, String name)
11        throws IOException {
12      InputStream is = clazz.getResourceAsStream(name);
13  
14      if (is == null)
15        throw new FileNotFoundException(name + ": is it in CLASSPATH?");
16  
17      Properties them = new Properties();
18      try {
19        them.load(is);
20      }
21      catch (IOException e) {
22        throw new IOException("Corrupt properties file `" + name + "': " +
23                              e.getMessage());
24      }
25      return them;
26    }
27  }