IT/WEB

[JAVA] Properties 클래스

오달달씨 2021. 4. 19. 11:35
728x90
반응형

Properties 클래스

 

특징

  • Properties 클래스는 HashaTabkes 클래스를 상속받았다. Properties 클래스는 Key와 Value를 갖는다.
  • Properties 클래스는 파일 입출력을 지원한다.
  • key=value 형식으로 작성 된 파일을 key와 value로 나누어 저장, 출력할 때 유용하다.

 

메서드 종류

1. void load(FileInputStream file) / load(FileReader file) : 스트림으로 열린 Properties 파일 객체를 로드함

2. String getProperty(String key) : key값을 제공하면 해당하는 value를 문자열로 변환함

3. Object setProperty(String key, value) : Properties 객체에 키와 값 저장

4. void store(스트림객체, 주석) : 객체에 저장된 내용을 파일에 씀(OutPutStream, Writer 계열만 가능)

 

FileInputStream fis = new FileInputStream();
Properties pp = new Properties();

fis = FileInputStream(
DTO.getConfig_path() + File.separator + "conf" + File.separator + "config.properties");
pp.load(fis);

DTO.setSKTL_business_time(pp.getProperty("SKTL_business_time"));

pp.setProperty("last_per_update", DTO.getLast_per_update());

pp.store(new FileOutputStream(
			DTO.getConfig_path() + File.separator + "conf" + File.separator + "config.properties"), "");

 

 

728x90
반응형