System中的getProperties方法使用

来源:互联网 发布:windows ce iso 编辑:程序博客网 时间:2024/05/16 14:48

1.我们可以使用System中提供的方法获取系统,用户的参数

public class OS {

    public static void main(String args[])
    {
        String OsName=System.getProperty("os.name");//操作系统名称
        String OsArch=System.getProperty("os.arch");//操作系统的构架
        String OsVersion=System.getProperty("os.version");//操作系统版本
        String JavaVendorUrl=System.getProperty("java.vendor.url");//供应商url
        String UserName=System.getProperty("user.name");
        System.out.println("操作系统的名称:"+OsName);
        System.out.println("操作系统构架:"+OsArch);
        System.out.println("操作系统版本:"+OsVersion);
        System.out.println("供应商 url:"+JavaVendorUrl);
        System.out.println("用户名:"+UserName);
    }

}

2.

public static Properties getProperties()
Determines the current system properties.

First, if there is a security manager, its checkPropertiesAccess method is called with no arguments. This may result in a security exception.

The current set of system properties for use by the getProperty(String) method is returned as a Properties object. If there is no current set of system properties, a set of system properties is first created and initialized. This set of system properties always includes values for the following keys:

KeyDescription of Associated Valuejava.versionJava Runtime Environment versionjava.vendorJava Runtime Environment vendorjava.vendor.urlJava vendor URLjava.homeJava installation directoryjava.vm.specification.versionJava Virtual Machine specification versionjava.vm.specification.vendorJava Virtual Machine specification vendorjava.vm.specification.nameJava Virtual Machine specification namejava.vm.versionJava Virtual Machine implementation versionjava.vm.vendorJava Virtual Machine implementation vendorjava.vm.nameJava Virtual Machine implementation namejava.specification.versionJava Runtime Environment specification versionjava.specification.vendorJava Runtime Environment specification vendorjava.specification.nameJava Runtime Environment specification namejava.class.versionJava class format version numberjava.class.pathJava class pathjava.library.pathList of paths to search when loading librariesjava.io.tmpdirDefault temp file pathjava.compilerName of JIT compiler to usejava.ext.dirsPath of extension directory or directoriesos.nameOperating system nameos.archOperating system architectureos.versionOperating system versionfile.separatorFile separator ("/" on UNIX)path.separatorPath separator (":" on UNIX)line.separatorLine separator ("\n" on UNIX)user.nameUser's account nameuser.homeUser's home directoryuser.dirUser's current working directory

Multiple paths in a system property value are separated by the path separator character of the platform.

Note that even if the security manager does not permit the getProperties operation, it may choose to permit thegetProperty(String) operation.

Returns:
the system properties
Throws:
SecurityException - if a security manager exists and itscheckPropertiesAccess method doesn't allow access to the system properties.
See Also:
setProperties(java.util.Properties),SecurityException, SecurityManager.checkPropertiesAccess(), Properties

0 0
原创粉丝点击