Mega Code Archive

 
Categories / Java Tutorial / Collections
 

Load a properties file in the startup directory

import java.io.File; import java.io.FileInputStream; import java.util.Properties; public class Main {   public static void main(String args[]) throws Exception {     Properties props = new Properties();     props = new java.util.Properties();     String path = new Main().getClass().getProtectionDomain().getCodeSource().getLocation()         .toString().substring(6);     FileInputStream fis = new FileInputStream(new File(path + "\\myprops.props"));     props.load(fis);     System.out.println(props);   } }