[Java] 외부 프라퍼티(XML) 파일 설정 정보 읽기

ITWeb/개발일반 2016. 3. 3. 16:30

외부에 존재하는 properties 파일이나 xml 파일에서 설정 정보를 읽고 싶을 경우가 있습니다.

그래서 기록해 봅니다.


import java.io.*;

import java.util.Properties;


Properties properties = new Properties();

InputStreamReader isr = null;


try {

  isr = new InputStreamReader(new FileInputStream("/server/config/config.properties"), "UTF-8");

  properties.load(isr);

} finally {

  if (null != isr) {

    try {

      isr.close();

    } catch (IOException ex) {}

  }

}


System.out.println(properties.getProperty("프라퍼티명"));


xml을 읽고 싶을 경우 

properties.loadFromXML(InputStream in);

을 이용하시면 됩니다.


: