System.getProperty()
ตัวอย่าง เช่น
package com.demo; import java.util.Properties; /** * @author nopphanan7 * */ public class SystemDemo { /** * @param args */ public static void main(String[] args) { System.out.println(System.getProperty("os.name")); // ตัวแปรคือ os.name } }
ค่าที่ได้คือ
Windows 7
นอกจากนี้ java ยังมี properties อื่นๆให้เรียกใช้อีกหลายตัว เช่น
package com.demo; import java.util.Properties; /** * @author nopphanan7 * */ public class SystemDemo { /** * @param args */ public static void main(String[] args) { // this will list the current system properties Properties p = System.getProperties(); p.list(System.out); } }ผลลัพย์คือ
-- listing properties -- java.runtime.name=Java(TM) SE Runtime Environment sun.boot.library.path=C:\Program Files\Java\jre6\bin java.vm.version=20.45-b01 java.vm.vendor=Sun Microsystems Inc. java.vendor.url=http://java.sun.com/ path.separator=; java.vm.name=Java HotSpot(TM) 64-Bit Server VM file.encoding.pkg=sun.io user.country=US sun.java.launcher=SUN_STANDARD sun.os.patch.level=Service Pack 1 java.vm.specification.name=Java Virtual Machine Specification user.dir=D:\workspace\testjava java.runtime.version=1.6.0_45-b06 java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment java.endorsed.dirs=C:\Program Files\Java\jre6\lib\endorsed os.arch=amd64 java.io.tmpdir=C:\Users\NOPPHA~1\AppData\Local\Temp\ line.separator= java.vm.specification.vendor=Sun Microsystems Inc. user.variant= os.name=Windows 7 // จากตัวอย่าง sun.jnu.encoding=MS874 java.library.path=C:\Program Files\Java\jre6\bin;C:\Win... java.specification.name=Java Platform API Specification java.class.version=50.0 sun.management.compiler=HotSpot 64-Bit Tiered Compilers os.version=6.1 user.home=C:\Users\nopphanan7 user.timezone= java.awt.printerjob=sun.awt.windows.WPrinterJob file.encoding=MS874 java.specification.version=1.6 user.name=nopphanan7 java.class.path=D:\workspace\testjava\bin java.vm.specification.version=1.0 sun.arch.data.model=64 java.home=C:\Program Files\Java\jre6 sun.java.command=com.demo.SystemDemo java.specification.vendor=Sun Microsystems Inc. user.language=en awt.toolkit=sun.awt.windows.WToolkit java.vm.info=mixed mode java.version=1.6.0_45 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=amd64
0 comments:
Post a Comment