Properties파일은 Key, Value값으로 부가적인 정보를 정의해 놓고, 불러와서 Map에 저장해 놓고 사용한다.
A=hello
B=properties
우선 pro.properties 파일을 만들고 값은 위 처럼 저장해 놓는다. 그리고 아래 처럼 값을 읽어온다.
Properties properties = new Properties();
properties.load(new FileInputStream("pro.properties"));
Enumeration<Object> enumeration = properties.keys();
while(enumeration.hasMoreElements()){
String key = (String) enumeration.nextElement();
String value = properties.getProperty(key);
System.out.println(key + " : " + value);
}
보통 예전에는 JDBC를 할때 DB접속 정보라던지 SQL구문을 코드와 분리시키기 위해 Properties에 저장해놓고 많이 썼었다.
read=select ... 이런식으로 저장하고 코드에서 Map에 저장 해놓고 비즈니스 로직을 수행할때 알맞은 sql을 Map에서 불러와 사용한다.
'Programinng > Java' 카테고리의 다른 글
자바(Java) - Reflection 리플렉션 (RTTI : Run-Time Type Information) (0) | 2012.12.15 |
---|---|
자바(Java) - Generic 제너릭 (0) | 2012.12.15 |
자바(Java) - null을 반환하면 안된다. (NullPointerException) (0) | 2012.12.15 |
자바(Java) - Annotation 어노테이션 (0) | 2012.12.15 |
자바(Java) - HttpClient 통신 <Get, Post, DefaultHttpClient> (0) | 2012.12.15 |