learning java 獲取環境變量及系統屬性


通過System.getenv( ) 獲取環境變量

通過System.getProperties() 獲取系統屬情

通過System.currentTimeMillis()  System.nanoTime() 獲取系統時間毫秒及納秒 

        Map<String, String> env = System.getenv();
        for(var name: env.keySet()){
            //System.out.println( name  + "------->" + env.get(name));
        }
        // 獲取JAVA_HOME變量
        System.out.println(System.getenv("JAVA_HOME"));
        
        Properties props = System.getProperties();
        props.store(new FileOutputStream("props.txt"), "System Properties");
        // 獲取系統屬情os.name =  window 10
        System.out.println(System.getProperty("os.name"));
        // 獲取距1970年1月1日的毫秒及納秒數值
        System.out.println(System.currentTimeMillis());
        System.out.println(System.nanoTime());

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM