본문 바로가기

Job/Java

[Java] System 클래스 getProperties()

import java.util.*;
public class GetProperties{
 public static void main(String[] args){

 

  System.setProperty("addProperty", "Test System Method");
  Properties prop = System.getProperties();

 

  Set key = prop.keySet();
  Iterator it = key.iterator();

 

  while(it.hasNext()){
   String curKey = it.next().toString();
   System.out.format("%s=%s\n", curKey, prop.getProperty(curKey));


  }
 }

}

 

 /*
    - static Properties getProperties();
      현재 자바프로퍼티 값들을 받아온다.

 

    - static String getProperty(String key);
      key에 지정된 자바 프로퍼티 값을 받아온다.

 

    - static String getProperty(String key, String def);
      key에 지정된 자바 프로퍼티 값을 받아온다.
      def는 해당 key가 존재하지 않을 경우 지정할 기본값이다.

 

   - static void setProperties(Properties props);
      props 객체에 담겨있는 내용을 자바 프로퍼티에 지정한다.

 

    - static String setProperty(String key, String value);
      자바 프로퍼티에 있는 지정된 key의 값을 value 값으로 변환한다.

 

      "addProperty" 라는 키를 갖는 시스템 프로퍼티에 "Test System Method" 라는
      값을 지정한 후, 시스템 프로퍼티 전체값을 화면에 출력해 주는 프로그램이다.
      이 프로그램을 수행하면 수십 개의 자바의 시스템 프로퍼티를 출력한다. 그 결과
      중 우리가 지정한 "addProperty" 키를 갖고 "Test System Method" 값을 가지는
      프로퍼티가 추가되어 출력될 것이다.
 */