zoukankan      html  css  js  c++  java
  • java中System.getProperties()与System.getEnv()

    其实在运行虚拟机时,经常一些虚拟机参数或者系统参数

    getEnv()方法

    System.getEnv()可以获取到我们在操作系统中的设置的一些环境变量

    public static void testGetEnv() {
            Map<String, String> env = System.getenv();
            for(String key:env.keySet()) {
                System.out.println(key+"="+env.get(key));
            }
        }

    结果运行

    USERDOMAIN_ROAMINGPROFILE=LAPTOP-L8MRCMCM
    LOCALAPPDATA=C:Usershua'weiAppDataLocal
    PROCESSOR_LEVEL=6
    USERDOMAIN=LAPTOP-L8MRCMCM
    FPS_BROWSER_APP_PROFILE_STRING=Internet Explorer
    LOGONSERVER=\LAPTOP-L8MRCMCM
    JAVA_HOME=D:programjdk-15
    SESSIONNAME=Console
    ALLUSERSPROFILE=C:ProgramData
    PROCESSOR_ARCHITECTURE=AMD64
    PSModulePath=C:Program FilesWindowsPowerShellModules;C:Windowssystem32WindowsPowerShellv1.0Modules
    SystemDrive=C:
    MAVEN_HOME=D:programapache-maven-3.6.3
    OneDrive=C:Usershua'weiOneDrive
    APPDATA=C:Usershua'weiAppDataRoaming
    USERNAME=hua'wei
    ProgramFiles(x86)=C:Program Files (x86)
    CommonProgramFiles=C:Program FilesCommon Files
    Path=D:/program/sts-4.8.0.RELEASE//plugins/org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_14.0.2.v20200815-0932/jre/bin/server;D:/program/sts-4.8.0.RELEASE//plugins/org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_14.0.2.v20200815-0932/jre/bin;D:programvmware_workstationin;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:WindowsSystem32OpenSSH;C:Program Files (x86)NVIDIA CorporationPhysXCommon;C:Program FilesNVIDIA CorporationNVIDIA NvDLISR;D:programjdk-15in;D:programjdk-15jrein;D:programapache-maven-3.6.3in;D:programmysql-8.0.21-winx64in;C:Usershua'weiAppDataLocalMicrosoftWindowsApps;C:Program FilesBandizip;D:programsts-4.8.0.RELEASE;
    FPS_BROWSER_USER_PROFILE_STRING=Default
    PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
    DriverData=C:WindowsSystem32DriversDriverData
    OS=Windows_NT
    classpath=.;D:programjdk-15lib;D:programjdk-15lib	ools.jar 
    COMPUTERNAME=LAPTOP-L8MRCMCM
    

    上述的输出结果有的是系统自带的环境变量,有的是我们自己设置的系统变量.

    getProperties()方法

    getProperties()方法可以获取到java虚拟机方面的参数

        public static void testGetProperties() {
            Properties properties = System.getProperties();
            for(Object key:properties.keySet()) {
                Object object = properties.get(key);
                System.out.println(key+"="+object);
            }
        }

    输出结果

    java.specification.version=15
    sun.cpu.isalist=amd64
    sun.jnu.encoding=GBK
    java.class.path=D:workspacealgorithm-pro	argetclasses
    java.vm.vendor=Oracle Corporation
    sun.arch.data.model=64
    user.variant=
    java.vendor.url=https://java.oracle.com/
    java.vm.specification.version=15
    os.name=Windows 10
    sun.java.launcher=SUN_STANDARD
    user.country=CN
    sun.boot.library.path=D:programjdk-15in
    sun.java.command=com.resource.location.SystemDemo
    jdk.debug=release
    sun.cpu.endian=little
    user.home=C:Usershua'wei
    user.language=zh
    java.specification.vendor=Oracle Corporation
    java.version.date=2020-09-15
    java.home=D:programjdk-15
    file.separator=
    java.vm.compressedOopsMode=Zero based
    line.separator=
    
    java.vm.specification.vendor=Oracle Corporation
    java.specification.name=Java Platform API Specification
    user.script=
    sun.management.compiler=HotSpot 64-Bit Tiered Compilers
    java.runtime.version=15+36-1562
    user.name=hua'wei
    path.separator=;
    os.version=10.0
    java.runtime.name=Java(TM) SE Runtime Environment
    file.encoding=UTF-8
    java.vm.name=Java HotSpot(TM) 64-Bit Server VM
    java.vendor.url.bug=https://bugreport.java.com/bugreport/
    java.io.tmpdir=C:Usershua'weiAppDataLocalTemp
    java.version=15
    user.dir=D:workspacealgorithm-pro
    os.arch=amd64
    java.vm.specification.name=Java Virtual Machine Specification
    sun.os.patch.level=
    java.library.path=D:programjdk-15in;C:WindowsSunJavain;C:Windowssystem32;C:Windows;D:/program/sts-4.8.0.RELEASE//plugins/org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_14.0.2.v20200815-0932/jre/bin/server;D:/program/sts-4.8.0.RELEASE//plugins/org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_14.0.2.v20200815-0932/jre/bin;D:programvmware_workstationin;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:WindowsSystem32OpenSSH;C:Program Files (x86)NVIDIA CorporationPhysXCommon;C:Program FilesNVIDIA CorporationNVIDIA NvDLISR;D:programjdk-15in;D:programjdk-15jrein;D:programapache-maven-3.6.3in;D:programmysql-8.0.21-winx64in;C:Usershua'weiAppDataLocalMicrosoftWindowsApps;C:Program FilesBandizip;D:programsts-4.8.0.RELEASE;;.
    java.vm.info=mixed mode, sharing
    java.vendor=Oracle Corporation
    java.vm.version=15+36-1562
    sun.io.unicode.encoding=UnicodeLittle
    java.class.version=59.0
  • 相关阅读:
    关于JS动态切换样式表
    关于header()函数重定向的问题
    微信团队讲课笔记 Android 开发(二)UI设计
    Effective C++ 笔记:4设计与声明
    某面试算法题_最短时间找出十包粉末中的两蓝粉末。
    VS2015 配置opengl的一些库
    URAL 1225 Flags 简单DP,一重循环
    POJ 1384 Piggy-Bank 完全背包分析
    POJ 1651 Multiplication Puzzle DP 类似矩阵链
    URAL 1183 Brackets Sequence DP 路径输出
  • 原文地址:https://www.cnblogs.com/cplinux/p/14052691.html
Copyright © 2011-2022 走看看