웹개발자/java

java convert properties to map 프로퍼티스 map 으로 읽어들이기

wlsufld 2018. 3. 14. 10:31

public static void main(String[] args) {
	Map map = new HashMap();
	System.out.println("==============get properties==============");
	map = getMyProperties("/test/db.properties");
}

//프로퍼티스 파일 읽어.
public static Map getMyProperties(String propertiesFile){
	Properties properties = new Properties();
	Map map = new HashMap();
	
	try {
		properties.load(new FileInputStream(propertiesFile));
		 for (String key : properties.stringPropertyNames()) {
				map.put(key, properties.getProperty(key));
		   }
		
	} catch (IOException e) {
		  e.printStackTrace();
	}
	return map;
}