Reputation: 5732
How can I access a property file called test.property
in user.home
?
This doesn't work:
public class Properties {
private static java.util.Properties p = new java.util.Properties();
static {
try {
String home = System.getProperty("user.home");
home += "\\test.properties";
System.out.println("User home: " + home);
InputStream is = Properties.class.getResourceAsStream(home);
p.load(is);
} catch (FileNotFoundException e) {
System.out.println("property file could not be found!");
} catch (IOException e) {
e.printStackTrace();
}
}
}
Upvotes: 1
Views: 4949
Reputation: 168825
File propsFile = new File(home, "test.properties");
InputStream is = new FileInputStream(propsFile);
You will probably find that the user.home
is not on the run-time class-path of the application. In that case, use a File
instead.
Upvotes: 1