JAVA
System클래스 (getProperty)
연93
2022. 10. 7. 21:27
시스템 프로퍼티란?
JVM이 시작할 때 자동 설정되는 시스템의 속성값
import java.util.Properties;
import java.util.Set;
public class GetPropertyExample {
public static void main(String[] args) {
// TODO Auto-generated method stub
String osName = System.getProperty("os.name");
String userName = System.getProperty("user.name");
String userHome = System.getProperty("user.home");
System.out.println("운영체제이름: " + osName);
System.out.println("사용자 이름: " + userName);
System.out.println("사용자 홈디렉토리: " + userHome);
System.out.println("----------------------------");
System.out.println(" [ key ] value");
System.out.println("----------------------------");
//컬렉션에서 설명.
// JVM 구동시 자동설정된 속성정보목록.
Properties props = System.getProperties();
Set keys = props.keySet();
for(Object objKey : keys) {
String key = (String) objKey;
String value = System.getProperty(key);
System.out.println("[ " + key + " ]" + value);
}
}
}