Java之getProperty中都有什么key?

最近在做一个小工具,之前的工具虽然能检测网址是否合法,能判断能否连接。但是还不足够,后面会另外写一篇关于工具改进的文章,能输出下载资源的名称,因为url本身会跳转到对应的下载资源,我需要核对这些东西下载是否正确。


工具本身写得巧妙,将地址复制进txt文件。我自己在看源码之前在想着实现思路。


bat控制编译,数据从txt读取,唯一让我想不明白的是为什么无论我放到哪里,他都能读取到txt文件的位置,这是我想不到的地方,但是看了源码之后就恍然大悟了。其实使用了System.getProperty("user.dir")获取了相对路径,出于兴趣,我又找到了jdk里面的说明,同时最近重新看了properties的操作,对于遍历基本就是信手拈来。


public class TestProperties {
	public static void main(String[] args) {
		Properties p = System.getProperties();
		Enumeration keys = p.keys();
		while(keys.hasMoreElements()){
			String s = (String) keys.nextElement();
			System.out.println("key: "+s);
			System.out.println("value: "+p.getProperty(s));
		}
	}
}

看一下输出:

key: java.runtime.name
value: Java(TM) SE Runtime Environment
key: sun.boot.library.path
value: C:\Program Files\Java\jdk1.7.0_67\jre\bin
key: java.vm.version
value: 24.65-b04
key: java.vm.vendor
value: Oracle Corporation
key: java.vendor.url
value: http://java.oracle.com/
key: path.separator
value: ;
key: java.vm.name
value: Java HotSpot(TM) 64-Bit Server VM
key: file.encoding.pkg
value: sun.io
key: user.country
value: CN
key: user.script
value: 
key: sun.java.launcher
value: SUN_STANDARD
key: sun.os.patch.level
value: Service Pack 1
key: java.vm.specification.name
value: Java Virtual Machine Specification
key: user.dir
value: E:\workspace\TestNet
key: java.runtime.version
value: 1.7.0_67-b01
key: java.awt.graphicsenv
value: sun.awt.Win32GraphicsEnvironment
key: java.endorsed.dirs
value: C:\Program Files\Java\jdk1.7.0_67\jre\lib\endorsed
key: os.arch
value: amd64
key: java.io.tmpdir
value: C:\Users\ADMINI~1\AppData\Local\Temp\
key: line.separator
value: 

key: java.vm.specification.vendor
value: Oracle Corporation
key: user.variant
value: 
key: os.name
value: Windows 7
key: sun.jnu.encoding
value: GBK
key: java.library.path
value: C:\Program Files\Java\jdk1.7.0_67\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;D:\tomcat7\lib;D:\tomcat7\bin;D:\ant1.8.2\bin;C:\Program Files\Java\jdk1.7.0_67\bin;C:\Program Files\TortoiseSVN\bin;D:\jar\apache-maven-3.2.3-bin\bin;D:\Program Files\AppServ\Apache2.2\bin;D:\Program Files\AppServ\php6;D:\Program Files\AppServ\MySQL\bin;.
key: java.specification.name
value: Java Platform API Specification
key: java.class.version
value: 51.0
key: sun.management.compiler
value: HotSpot 64-Bit Tiered Compilers
key: os.version
value: 6.1
key: user.home
value: C:\Users\Administrator
key: user.timezone
value: 
key: java.awt.printerjob
value: sun.awt.windows.WPrinterJob
key: file.encoding
value: UTF-8
key: java.specification.version
value: 1.7
key: java.class.path
value: E:\workspace\TestNet\bin
key: user.name
value: Administrator
key: java.vm.specification.version
value: 1.7
key: sun.java.command
value: TestProperties
key: java.home
value: C:\Program Files\Java\jdk1.7.0_67\jre
key: sun.arch.data.model
value: 64
key: user.language
value: zh
key: java.specification.vendor
value: Oracle Corporation
key: awt.toolkit
value: sun.awt.windows.WToolkit
key: java.vm.info
value: mixed mode
key: java.version
value: 1.7.0_67
key: java.ext.dirs
value: C:\Program Files\Java\jdk1.7.0_67\jre\lib\ext;C:\Windows\Sun\Java\lib\ext
key: sun.boot.class.path
value: C:\Program Files\Java\jdk1.7.0_67\jre\lib\resources.jar;C:\Program Files\Java\jdk1.7.0_67\jre\lib\rt.jar;C:\Program Files\Java\jdk1.7.0_67\jre\lib\sunrsasign.jar;C:\Program Files\Java\jdk1.7.0_67\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.7.0_67\jre\lib\jce.jar;C:\Program Files\Java\jdk1.7.0_67\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.7.0_67\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.7.0_67\jre\classes
key: java.vendor
value: Oracle Corporation
key: file.separator
value: \
key: java.vendor.url.bug
value: http://bugreport.sun.com/bugreport/
key: sun.io.unicode.encoding
value: UnicodeLittle
key: sun.cpu.endian
value: little
key: sun.desktop
value: windows
key: sun.cpu.isalist
value: amd64

各个key的说明

Key Description of Associated Value 
java.version Java Runtime Environment version 
java.vendor Java Runtime Environment vendor 
java.vendor.url Java vendor URL 
java.home Java installation directory 
java.vm.specification.version Java Virtual Machine specification version 
java.vm.specification.vendor Java Virtual Machine specification vendor 
java.vm.specification.name Java Virtual Machine specification name 
java.vm.version Java Virtual Machine implementation version 
java.vm.vendor Java Virtual Machine implementation vendor 
java.vm.name Java Virtual Machine implementation name 
java.specification.version Java Runtime Environment specification version 
java.specification.vendor Java Runtime Environment specification vendor 
java.specification.name Java Runtime Environment specification name 
java.class.version Java class format version number 
java.class.path Java class path 
java.library.path List of paths to search when loading libraries 
java.io.tmpdir Default temp file path 
java.compiler Name of JIT compiler to use 
java.ext.dirs Path of extension directory or directories 
os.name Operating system name 
os.arch Operating system architecture 
os.version Operating system version 
file.separator File separator ("/" on UNIX) 
path.separator Path separator (":" on UNIX) 
line.separator Line separator ("\n" on UNIX) 
user.name User's account name 
user.home User's home directory 
user.dir User's current working directory 


然后让我想起了很久以前阿包给的一个方法,sun.arch.data.model其实查看的是操作系统的架构,就是你windows或者其他OS是几位的。


System.getProperty("user.dir")获取当前工作路径的方法也很是实用。

你可能感兴趣的:(Java)