9.34.2.使用系统属性 using properties

import java.io.FileInputStream;
import java.util.Properties;
public class PropertiesTest2{
	public static void main(String[] args) throws Exception{
		Properties properties = System.getProperties();//确定当前系统属性
		properties.list(System.out);//属性的清单、列表
		
		FileInputStream in = null;
		in = new FileInputStream(args[0]);
		properties.load(in);
		
		System.getProperties().list(System.out);
		System.out.println("\nValue of local.animal.defined is" + Boolean.getBoolean("local.animal.defined"));
		System.out.println("\nValue of local.animal.legcount is" + Integer.getInteger("local.animal.legcount"));
	}
}

-- listing properties --
java.runtime.name=Java(TM) SE Runtime Environment
sun.boot.library.path=C:\Program Files\Java\jre6\bin
java.vm.version=20.1-b02
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=Service Pack 3
java.vm.specification.name=Java Virtual Machine Specification
user.dir=E:\java\Test
java.runtime.version=1.6.0_26-b03
java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs=C:\Program Files\Java\jre6\lib\endorsed
os.arch=x86
java.io.tmpdir=C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\
line.separator=

java.vm.specification.vendor=Sun Microsystems Inc.
user.variant=
os.name=Windows XP
sun.jnu.encoding=GBK
java.library.path=C:\WINDOWS\system32;C:\WINDOWS\Sun\Ja...
java.specification.name=Java Platform API Specification
java.class.version=50.0
sun.management.compiler=HotSpot Client Compiler
os.version=5.1
user.home=C:\Documents and Settings\Administrator
user.timezone=
java.awt.printerjob=sun.awt.windows.WPrinterJob
file.encoding=GBK
java.specification.version=1.6
user.name=Administrator
java.class.path=.;C:\Program Files\Java\jre6\lib\ext\...
java.vm.specification.version=1.0
sun.arch.data.model=32
java.home=C:\Program Files\Java\jre6
sun.java.command=PropertiesTest2
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_26
java.ext.dirs=C:\Program Files\Java\jre6\lib\ext;C:...
sun.boot.class.path=C:\Program Files\Java\jre6\lib\resour...
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...
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
        at PropertiesTest2.main(PropertiesTest2.java:9)

阅读更多
个人分类: 9.集合 Collections
上一篇插入时间值
下一篇9.34.6.用Strore存储 Use store() to save the properties
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭