程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> JAVA綜合教程 >> 取得系統屬性和Java環境,取得java環境

取得系統屬性和Java環境,取得java環境

編輯:JAVA綜合教程

取得系統屬性和Java環境,取得java環境


代碼如下:

import java.util.Enumeration;

import java.util.Iterator;

import java.util.Map;

import java.util.Map.Entry;

import java.util.Properties;

import java.util.Set;

 

public class Test {

 

    @SuppressWarnings("unchecked")

    public static void main(String[] args) {

        System.out.println("系統環境如下:");

        Map<String, String> map = System.getenv();

        Set<Entry<String, String>> set = map.entrySet();

        Iterator<Entry<String, String>> iter = set.iterator();

        while (iter.hasNext()) {

            Entry<String, String> ent = iter.next();

            System.out.println(ent.getKey() + "\n ->" + ent.getValue());

        }

        System.out.println("------------分割線------------------");

        System.out.println("Java屬性如下:");

        Properties p = System.getProperties();

        Enumeration<String> enu = (Enumeration<String>) p.propertyNames();

        while (enu.hasMoreElements()) {

            String s = enu.nextElement();

            System.out.println(s + "\n ->" + System.getProperty(s));

        }

 

    }

 

}

 

我的輸出如下:

系統環境如下:

LOCALAPPDATA

->C:\Users\zz\AppData\Local

PROCESSOR_LEVEL

->6

FP_NO_HOST_CHECK

->NO

USERDOMAIN

->zz-PC

LOGONSERVER

->\\ZZ-PC

SESSIONNAME

->Console

ALLUSERSPROFILE

->C:\ProgramData

PROCESSOR_ARCHITECTURE

->AMD64

PSModulePath

->C:\Windows\system32\WindowsPowerShell\v1.0\Modules\

SystemDrive

->C:

APPDATA

->C:\Users\zz\AppData\Roaming

USERNAME

->zz

windows_tracing_logfile

->C:\BVTBin\Tests\installpackage\csilogfile.log

ProgramFiles(x86)

->C:\Program Files (x86)

CommonProgramFiles

->C:\Program Files\Common Files

Path

->C:/Program Files/Java/jre1.8.0_102/bin/server;C:/Program Files/Java/jre1.8.0_102/bin;C:/Program Files/Java/jre1.8.0_102/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;D:\MySoft\mysql-5.7.15-winx64\bin;C:\Program Files\Calibre2\;D:\MySoft\eclipse;

PATHEXT

->.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

OS

->Windows_NT

windows_tracing_flags

->3

COMPUTERNAME

->ZZ-PC

PROCESSOR_REVISION

->2a07

CommonProgramW6432

->C:\Program Files\Common Files

ComSpec

->C:\Windows\system32\cmd.exe

ProgramData

->C:\ProgramData

ProgramW6432

->C:\Program Files

HOMEPATH

->\Users\zz

SystemRoot

->C:\Windows

TEMP

->C:\Users\zz\AppData\Local\Temp

MYSQL_HOME

->D:\MySoft\mysql-5.7.15-winx64

HOMEDRIVE

->C:

PROCESSOR_IDENTIFIER

->Intel64 Family 6 Model 42 Stepping 7, GenuineIntel

USERPROFILE

->C:\Users\zz

TMP

->C:\Users\zz\AppData\Local\Temp

CommonProgramFiles(x86)

->C:\Program Files (x86)\Common Files

ProgramFiles

->C:\Program Files

PUBLIC

->C:\Users\Public

NUMBER_OF_PROCESSORS

->4

windir

->C:\Windows

=::

->::\

------------分割線------------------

Java屬性如下:

java.runtime.name

->Java(TM) SE Runtime Environment

sun.boot.library.path

->C:\Program Files\Java\jre1.8.0_102\bin

java.vm.version

->25.102-b14

java.vm.vendor

->Oracle Corporation

java.vendor.url

->http://java.oracle.com/

path.separator

->;

java.vm.name

->Java HotSpot(TM) 64-Bit Server VM

file.encoding.pkg

->sun.io

user.script

->

user.country

->CN

sun.java.launcher

->SUN_STANDARD

sun.os.patch.level

->Service Pack 1

java.vm.specification.name

->Java Virtual Machine Specification

user.dir

->D:\MySoft\WorkSpace\EMProject

java.runtime.version

->1.8.0_102-b14

java.awt.graphicsenv

->sun.awt.Win32GraphicsEnvironment

java.endorsed.dirs

->C:\Program Files\Java\jre1.8.0_102\lib\endorsed

os.arch

->amd64

java.io.tmpdir

->C:\Users\zz\AppData\Local\Temp\

line.separator

->

 

java.vm.specification.vendor

->Oracle Corporation

user.variant

->

os.name

->Windows 7

sun.jnu.encoding

->GBK

java.library.path

->C:\Program Files\Java\jre1.8.0_102\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre1.8.0_102/bin/server;C:/Program Files/Java/jre1.8.0_102/bin;C:/Program Files/Java/jre1.8.0_102/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;D:\MySoft\mysql-5.7.15-winx64\bin;C:\Program Files\Calibre2\;D:\MySoft\eclipse;;.

java.specification.name

->Java Platform API Specification

java.class.version

->52.0

sun.management.compiler

->HotSpot 64-Bit Tiered Compilers

os.version

->6.1

user.home

->C:\Users\zz

user.timezone

->

java.awt.printerjob

->sun.awt.windows.WPrinterJob

file.encoding

->UTF-8

java.specification.version

->1.8

user.name

->zz

java.class.path

->D:\MySoft\WorkSpace\EMProject\WebContent\WEB-INF\classes;D:\MySoft\WorkSpace\EMProject\WebContent\WEB-INF\lib\SmartUpload.jar;D:\MySoft\WorkSpace\EMProject\WebContent\WEB-INF\lib\commons-beanutils-1.7.0.jar;D:\MySoft\WorkSpace\EMProject\WebContent\WEB-INF\lib\commons-collections-3.2.1.jar;D:\MySoft\WorkSpace\EMProject\WebContent\WEB-INF\lib\commons-httpclient-3.1.jar;D:\MySoft\WorkSpace\EMProject\WebContent\WEB-INF\lib\commons-lang-2.3.jar;D:\MySoft\WorkSpace\EMProject\WebContent\WEB-INF\lib\commons-logging-1.1.1.jar;D:\MySoft\WorkSpace\EMProject\WebContent\WEB-INF\lib\ezmorph-1.0.3.jar;D:\MySoft\WorkSpace\EMProject\WebContent\WEB-INF\lib\filters-2.0.235.jar;D:\MySoft\WorkSpace\EMProject\WebContent\WEB-INF\lib\javax.servlet.jsp.jstl.jar;D:\MySoft\WorkSpace\EMProject\WebContent\WEB-INF\lib\json-lib-2.2.3-jdk15.jar;D:\MySoft\WorkSpace\EMProject\WebContent\WEB-INF\lib\jsp-api.jar;D:\MySoft\WorkSpace\EMProject\WebContent\WEB-INF\lib\jstl-impl-1.2.2.jar;D:\MySoft\WorkSpace\EMProject\WebContent\WEB-INF\lib\kaptcha-0.0.9.jar;D:\MySoft\WorkSpace\EMProject\WebContent\WEB-INF\lib\mysql-connector-java-5.0.4-bin.jar;D:\MySoft\WorkSpace\EMProject\WebContent\WEB-INF\lib\servlet-api.jar

java.vm.specification.version

->1.8

sun.arch.data.model

->64

java.home

->C:\Program Files\Java\jre1.8.0_102

sun.java.command

->test.Test

java.specification.vendor

->Oracle Corporation

user.language

->zh

awt.toolkit

->sun.awt.windows.WToolkit

java.vm.info

->mixed mode

java.version

->1.8.0_102

java.ext.dirs

->C:\Program Files\Java\jre1.8.0_102\lib\ext;C:\Windows\Sun\Java\lib\ext

sun.boot.class.path

->C:\Program Files\Java\jre1.8.0_102\lib\resources.jar;C:\Program Files\Java\jre1.8.0_102\lib\rt.jar;C:\Program Files\Java\jre1.8.0_102\lib\sunrsasign.jar;C:\Program Files\Java\jre1.8.0_102\lib\jsse.jar;C:\Program Files\Java\jre1.8.0_102\lib\jce.jar;C:\Program Files\Java\jre1.8.0_102\lib\charsets.jar;C:\Program Files\Java\jre1.8.0_102\lib\jfr.jar;C:\Program Files\Java\jre1.8.0_102\classes

java.vendor

->Oracle Corporation

file.separator

->\

java.vendor.url.bug

->http://bugreport.sun.com/bugreport/

sun.cpu.endian

->little

sun.io.unicode.encoding

->UnicodeLittle

sun.desktop

->windows

sun.cpu.isalist

->amd64

 

簡化代碼:

System.getProperties().list(System.out);

        

Object[] str = System.getenv().keySet().toArray();

for(Object s:str){

    String temp = (String) s;

    System.out.println(temp+"="+System.getenv(temp));

}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved