Hyun CHO 2016. 12. 14. 17:00

import java.util.Enumeration;

import java.util.Properties;


public class PropertiesTest {


public PropertiesTest() {

//Key, value를 가진다.

//문자열을 저장하는 기능

Properties p = new Properties();

//  Key vlaue

//  index  값

p.setProperty("111", "AAA"); //데이터 추가

p.setProperty("222", "BBB");

p.setProperty("333", "CCC");

p.setProperty("444", "DDD");

//데이터 얻기

System.out.println(p.getProperty("222")+"\n==============");

//Properties 객체의 키값 가져오기

//Enumeration 은 키가 존재하지 않으며 객체는 순서대로 얻어와야 함.

Enumeration enumer = p.propertyNames();

//컬렉션에 남은 객체가 있늕니 확인

while(enumer.hasMoreElements()){

//컬렉션 객체 얻어오기

String key = (String)enumer.nextElement();

String value = p.getProperty(key);

System.out.println("key:"+key+", value:"+value);

}

}


public static void main(String[] args) {

new PropertiesTest();


}


}