System类

来源:互联网 发布:淘宝seo搜索优化技巧 编辑:程序博客网 时间:2024/06/15 20:32

特点:类中的方法和属性都为静态

常用方法:

static PropertiesgetProperties()
          确定当前的系统属性。static StringgetProperty(String key)
          获取指定键指示的系统属性。static StringsetProperty(String key,String value)
          设置指定键指示的系统属性。static longcurrentTimeMillis()
          返回以毫秒为单位的当前时间。

<table summary="" width="100%" cellspacing="0" cellpadding="3" border="1"><tbody><tr class="TableRowColor" bgcolor="white"><td width="1%" valign="top" align="right"><span size="-1" style=""><code>static void</code></span></td><td><code><strong><a target=_blank href="../../java/lang/System.html#exit(int)">exit</a></strong>(int status)</code>           终止当前正在运行的 Java 虚拟机。</td></tr></tbody></table>常用方法一 getProperties();//获取系统的属性信息,并存储到了Properties集合中。//properties集合中存储都是String类型的键和值。用它自己的存储和取出的方法来完成元素的操作Properties prop = System.getProperties(); Set<String> nameSet = prop.stringPropertyNames(); for(String name : nameSet){ String value = prop.getProperty(name); System.out.println(name+"::"+value); }

常用方法二演示:getPrroperty(String key);

键:

file.separator文件分隔符(在 UNIX 系统中是“/”)path.separator路径分隔符(在 UNIX 系统中是“:”)line.separator行分隔符(在 UNIX 系统中是“/n”)

<p>private static final String LINE_SEPARATOR = System.getProperty("line.separator");//全局常量:获取系统的换行符</p>System.out.println("hello-"+LINE_SEPARATOR+" world");

获取本地时间毫秒值:

System.currentTimeMillis();返回值为long型


0 0
原创粉丝点击