Tengo un proyecto java con la siguiente estructura:
Y mi clase que lee dichas propiedades
public class PropertyValues {
InputStream inputStream;
HashMap<String,String> mapResources;
public PropertyValues() throws IOException {
try {
Properties prop = new Properties();
String propFileName = "config.properties";
inputStream = getClass().getClassLoader().getResourceAsStream(propFileName);
if (inputStream != null) {
prop.load(inputStream);
} else {
throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath");
}
mapResources.put("rname", prop.getProperty("rname"));
mapResources.put("channel", prop.getProperty("channel"));
mapResources.put("serverdb", prop.getProperty("serverdb"));
mapResources.put("portdb", prop.getProperty("portdb"));
mapResources.put("dbname", prop.getProperty("dbname"));
mapResources.put("userdb", prop.getProperty("userdb"));
mapResources.put("passdb", prop.getProperty("passdb"));
mapResources.put("replicationname", prop.getProperty("replicationname"));
mapResources.put("tables", prop.getProperty("tables"));
} catch (Exception e) {
System.out.println("Exception: " + e);
} finally {
inputStream.close();
}
}
El source folder "Resources" yo lo creé y dentro mi config.properties, tal ahí no va, entonces dónde? Me marca null pointer exception.
Alguna idea?