I tried to read a .properties file and have code as following:
public final class Config {
static {
Properties properties = new Properties();
InputStream propertiesStream = Object.class.getResourceAsStream("config.properties");
if (propertiesStream != null) {
try {
properties.load(propertiesStream);
} catch (IOException e) {
e.printStackTrace();
}
} else {
System.out.println("file not found");
}
}
}
but it keeps saying file not found.
The content of properties is
pwd=passw0rd
Anyone knows how to solve this problem?
properties file inside your resource folder of the java project. The extension we use for the properties file is . properties.
The file must be present at /data/vcps/config/config. properties.
Right-click and select Add New Properties File. A new properties file will be added to your project. The new file will be selected and highlighted in the list.
It should be in classpath, put it to your root source package, if its a maven project put it to src/main/resources
directory
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With