樱花树苗种植技术:java 获取当前应用程序和系统的属性特征,比如路径、用户名..

来源:百度文库 编辑:偶看新闻 时间:2024/05/02 08:45:25
java 获取当前应用程序和系统的属性特征,比如路径、用户名..2011年05月29日 星期日 下午 2:58

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

通过这个你可以获得所有,其中在我的电脑中的所有信息如下:

-- listing properties --
java.runtime.name=Java(TM) SE Runtime Environment
sun.boot.library.path=G:\JDK\Java\jdk1.6.0_23\jre\bin
java.vm.version=19.0-b09
java.vm.vendor=Sun Microsystems Inc.
java.vendor.url=http://java.sun.com/
path.separator=;
java.vm.name=Java HotSpot(TM) Client VM
file.encoding.pkg=sun.io
user.country=CN
sun.java.launcher=SUN_STANDARD
sun.os.patch.level=
java.vm.specification.name=Java Virtual Machine Specification
user.dir=D:\JAVA\JavaApp\App1
java.runtime.version=1.6.0_23-b05
java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs=G:\JDK\Java\jdk1.6.0_23\jre\lib\endorsed
os.arch=x86
java.io.tmpdir=C:\Users\ADMINI~1\AppData\Local\Temp\
line.separator=

java.vm.specification.vendor=Sun Microsystems Inc.
user.variant=
os.name=Windows 7
sun.jnu.encoding=GBK
java.library.path=G:\JDK\Java\jdk1.6.0_23\bin;.;C:\Wind...
java.specification.name=Java Platform API Specification
java.class.version=50.0
sun.management.compiler=HotSpot Client Compiler
os.version=6.1
user.home=C:\Users\Administrator
user.timezone=
java.awt.printerjob=sun.awt.windows.WPrinterJob
file.encoding=GBK
java.specification.version=1.6
user.name=Administrator
java.class.path=D:\JAVA\JavaApp\App1\bin
java.vm.specification.version=1.0
sun.arch.data.model=32
java.home=G:\JDK\Java\jdk1.6.0_23\jre
java.specification.vendor=Sun Microsystems Inc.
user.language=zh
awt.toolkit=sun.awt.windows.WToolkit
java.vm.info=mixed mode, sharing
java.version=1.6.0_23
java.ext.dirs=G:\JDK\Java\jdk1.6.0_23\jre\lib\ext;C...
sun.boot.class.path=G:\JDK\Java\jdk1.6.0_23\jre\lib\resou...
java.vendor=Sun Microsystems Inc.
file.separator=\
java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport...
sun.cpu.endian=little
sun.io.unicode.encoding=UnicodeLittle
sun.desktop=windows
sun.cpu.isalist=pentium_pro+mmx pentium_pro pentium+m...

 

你至于如何获取特定的属性值,你可以如下操作:

System.getProperty("user.name")

这个user.name 属性键是怎么知道的呢?就是System.getProperties()上面获取到的list左边等号的字串。

这个操作对于获取当前应用程序的一些属性比较有用,比如当前系统用户名,程序路径,操作系统....