| Refresh | Home EGTry.com

load properties from classpath


We have the egtry.properties file that is located in the same directory as EGProperty.java, then we can load as following

package com.egtry;

public class EGProperty {

   public static void main(String[] args) {
     InputStream in=EGProperty.class.getResourceAsStream("egtry.properties");
     Properties prop=new Properties();
     try {
       prop.load(in);
     } catch (Exception e) {

     }
     System.out.println("name1="+prop.getProperty("name1");
     //value1
    }
}
   

 


egtry.properties

#comment
name1=value1