Monday, March 30, 2015

Location of properties file in Java application

props = new Properties();

props.load(getClass().getResourceAsStream("mail.properties"));

FileInputStream(..) in Java uses paths relative to the current user directory (see java.io.File documentation). So it looks for mail.properties in /home/usr/ or c:\documents and settings\usr. If your .properties file is on the application classpath you can read it throug the Class.getResourceAsStream(..) method.

Popular Posts

Labels

ad ( 3 ) Amazon ( 46 ) Answer ( 1 ) API ( 25 ) automation ( 1 ) blog ( 23 ) book ( 2 ) career ( 12 ) cdn ( 2 ) centos ( 1 ) cloud ( 123 ) CRM ( 24 ) current ( 13 ) data ( 14 ) database ( 64 ) design patterns ( 15 ) development ( 3 ) eCommerce ( 26 ) email ( 93 ) ETL ( 2 ) framework ( 3 ) git ( 9 ) google ( 179 ) IDE ( 14 ) Integration ( 1 ) interview ( 15 ) Java ( 392 ) Java EE ( 105 ) javascript ( 42 ) Jboss ( 4 ) JPA ( 48 ) JSF ( 45 ) linux ( 337 ) Marketing ( 19 ) mobile ( 44 ) model ( 1 ) MySQL ( 198 ) online money ( 14 ) OOP ( 7 ) open source ( 25 ) performance ( 72 ) php ( 51 ) python ( 46 ) quality ( 5 ) referral ( 3 ) restful ( 23 ) security ( 127 ) SEO ( 18 ) social ( 26 ) software ( 73 ) spam ( 4 ) Spring ( 1 ) SQL ( 22 ) system ( 32 ) testing ( 17 ) tool ( 90 ) UML ( 8 ) virtual ( 9 ) web ( 225 ) web services ( 14 ) WildFly ( 4 ) wordpress ( 9 )