【Java】System.getenv()で環境変数を取得するコード
Javaコード
import java.util.Map;
public class EnvInfoDemo {
public static void main(String[] args) {
Map<String, String> map = System.getenv();
String userName = map.get(“USERNAME");
String computerName = map.get(“COMPUTERNAME");
String userDomain = map.get(“USERDOMAIN");
System.out.println(
“userName:" + userName + “\n"
+ “computername:" + computerName + “\n"
+ “userdomain:" + userDomain);
}
}
実行結果
userName:yamada
computername:YAMADA-PC
userdomain:YAMADA-PC