Java中的System类

a、arraycopy方法

public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length)

该方法的作用是数组拷贝。

 

b、currentTimeMillis方法

public static long currentTimeMillis()

该方法的作用是返回当前的计算机时间,时间的表达格式为当前计算机时间和GMT时间(格林威治时间)1970年1月1号0时0分0秒所差的毫秒数。

 

c、exit方法

public static void exit(int status)

该方法的作用是退出程序。其中status的值为0代表正常退出,非零代表异常退出。使用该方法可以在图形界面编程中实现程序的退出功能等。

 

d、gc方法

 public static void gc()

该方法的作用是请求系统进行垃圾回收。至于系统是否立刻回收,则取决于系统中垃圾回收算法的实现以及系统执行时的情况.

 

e、getProperty方法
public static String getProperty(String key)
该方法的作用是获得系统中属性名为key的属性对应的值。

常用例子:

String osName = System.getProperty("os.name");

System.out.println("当前操作系统是:"+ osName);

String user = System.getProperty("user.name");

System.out.println("当前用户是:" + user);

String separator = System.getProperty("file.separator");

System.out.println("文件路径字符串的分隔符:" + separator);

String language = System.getProperty("user.language")

System.out.println("系统当前语言环境:" + language);

使用该方法可以获得很多系统级的参数以及对应的值。

 

posted @ 2017-04-24 21:22  N神3  阅读(283)  评论(0编辑  收藏  举报