package ch09;
import java.util.*;
public class Ch0906
{
public static void main(String[] args)
{
//Property
Properties pr = new Properties();
pr.put("게임","스타크래프트2");
pr.put("가수","조용필");
pr.put("영화","여고괴담5");
Iterator iter = pr.keySet().iterator();
//Enumeration enumer = pr.keys();
while(iter.hasNext())
{
String key = (String)iter.next();
//String value = (String)pr.get(key);
//.getPropety 자체적으로 String 반환.
String value = pr.getProperty(key);
System.out.println(key+" : "+value);
}
}
}
******* Ch0906.java *******
package ch09;
import java.util.*;
import java.io.*;
public class Ch0907
{
//선행조건 입력테이블.. 아직 안배웠으니, 있다는 정도만 알아두고..
//파일 생성.. 한글 설정해줘야되니. 일단 영어로..
public static void main(String[] args)
{
//Properties컬렉션은 properties화일을 읽어들여
//properties 컬렉션안에 요소를 저장하는 기능이 지원.
try
{
FileInputStream in = new FileInputStream("D:\\study\\java\\Project\\sample\\src\\ch09\\Ch0907.properties");
Properties pr = new Properties();
pr.load(in);
Iterator iter = pr.keySet().iterator();
while (iter.hasNext())
{
String key = (String)iter.next();
String value = (String)pr.getProperty(key);
System.out.println(key+" : "+value);
}
in.close();
}
catch (FileNotFoundException e)
{
//FileInputStream 파일이 없을시..
// TODO 자동 생성된 catch 블록
e.printStackTrace();
}
catch (IOException e)
{
//load 로드시..
// TODO 자동 생성된 catch 블록
e.printStackTrace();
}
}
}
***** Ch0907.properties ******
#Ch0907.properties
#ini File Setting.
movie=Wind Blows
book=Rain
sport=baseball