Reputation: 2265
I need to be able to read properties files using FileInoputStream. I have 3 properties files:
Properties props = new Properties();
Properties props2 = new Properties();
Properties props3 = new Properties();
FileInputStream ldapfis = new FileInputStream("/home/webserver/tomcat6/properties/js.ldap.properties");
FileInputStream smtpfis = new FileInputStream("/home/webserver/tomcat6/properties/js.smtp.properties");
FileInputStream dbfis = new FileInputStream("/home/webserver/tomcat6/properties/js.db.properties");
props.load(ldapfis);
props2.load(smtpfis);
props2.load(dbfis);
String host = props.getProperty("ldap.provider.host");
String dbName = props2.getProperty("db.name");
Is this how you do it in linux with absolute path? Is this ok to do?
Upvotes: 1
Views: 91
Reputation: 79875
It's not really OK to do this, because if you install tomcat in any other location, or even upgrade from tomcat6 to tomcat7, all your code will break.
I would recommend using the System.getProperty("CATALINA_HOME")
which should point to your tomcat home directory. You can then get a path based on that.
Upvotes: 1
Reputation: 2006
new FileInputStream("/home/webserver/tomcat6/properties/js.ldap.properties");
If a file path startswith slash (/) it will take this as a path.
but if file path is not startswith slash(/) , then it is a absolute path. It will try to append path with java home.
For Ex
new FileInputStream("properties/js.ldap.properties");
It will append java path home
Here if java home is /home/webserver/tomcat6/
it will try to find under /home/webserver/tomcat6/properties/js.ldap.properties
.
Upvotes: 1