properties 파일 작성
private static void writeProps () {
Properties prop = new Properties();
prop.setProperty("SERVER_IP", "127.0.0.1");
prop.setProperty("SERVER_PORT", "5000");
try {
OutputStream stream = new FileOutputStream("testProperty");
prop.store(stream, "SERVER INFO");
stream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
properties 파일 읽기
private static void readProps () {
Properties prop = new Properties();
try {
InputStream stream = new FileInputStream("testProperty");
prop.load(stream);
stream.close();
System.out.println(prop.getProperty("SERVER_IP"));
} catch (IOException e ){
}
}
결과
xml 파일을 properties 파일로 사용하기