lesson6.7System和Runtime
来源:互联网 发布:淘宝质量好的男装店 编辑:程序博客网 时间:2024/05/29 15:01
Java中不支持全局函数和变量,通常存放在System类中,都是静态的。
常用方法有:
exit(0);结束java虚拟机的运行,由于异常终止传入非零值,正常终止传入0
currentTimeMills();返回1970.1.1 00:00:00到当前时刻的时间,以毫秒为单位
getProperties();获得系统属性,返回Properties对象。
setProperties(Properties p);添加新的属性
习题:打印所有的系统属性
Runtime类封装的java虚拟机进程
一个java虚拟机对应一个Runtime对象,这个对象不能new哦
常用方法有:
Runtime.getRuntime();//获得Runtime对象的引用
exec("notepad.exe xxx.java");//启动子进程,返回Process类对象,参数是启动的应用程序和要打开的文件名
Process类有destory函数用来结束程序
习题:启动一个记事本五秒后关闭
import java.util.Enumeration;import java.util.Properties;public class testSystemRuntime {public static void main(String [] args){//打印出所有的系统属性变量Properties p = new Properties();p = System.getProperties();//获得系统属性,返回Properties对象Enumeration e = p.propertyNames();//获得所有关键字,返回Enumeration对象while(e.hasMoreElements()){String key = (String)e.nextElement();//取出关键字System.out.println(key+" = "+p.getProperty(key));//打印出关键字和值}//启动记事本实例,并打开java文件五秒后关闭Process pr = null;try{pr = Runtime.getRuntime().exec("notepad.exe testSystemRuntime.java");//先获得Runtime对象,才能启动一个子进程Thread.sleep(5000);pr.destroy();//关闭pr进程}catch(Exception ee){ee.printStackTrace();}}}ps:记得以前c老师说过c语言没有你不知道的,只有你不会调的,java是没有你不会调的,只有你不知道的,果然java应该是重在积累,c应该是重在理解吧。
阅读全文
0 0
- lesson6.7System和Runtime
- System和Runtime
- System类和RunTime类
- 13.2 System 和Runtime类
- System类和Runtime类
- Runtime.getRuntime(),System.getenv()和System.getProperty()
- lesson6.7Properties类
- runtime system
- system、runtime
- Runtime和System类的操作例子
- System、Runtime、Date和Galender、Math、Random
- 解析System.gc()和Runtime.gc()区别
- 7 System、Runtime、Date、Math、Random类
- lesson6.6PipedInputStream和ByteArrayInputStream类
- System 类 和 Runtime 类的常用用法
- System 类 和 Runtime 类的常用用法
- JAVA常用类之——System和Runtime
- 黑马程序员-Java基础其它对象(System和Runtime)
- Glide 实现圆形图片 并动态旋转
- BZOJ 2435: [Noi2011]道路修建 树的遍历-_-
- React-Native 0.43.4 undefined is not an object (evaluating '_props[registrationName]') 正确的解决姿势
- ubuntu 设置ssh连接
- 指针指向字符串,函数指针,多功能函数调用
- lesson6.7System和Runtime
- linux线程学习(3)
- Arcgis---坐标转换API
- Ubuntu16下编译安装Open Babel2.4.1和python绑定
- JavaScript入门基础--数据类型编程练习
- PHP自动捕获Exception,Fatal error等错误和异常
- WPF TabControl 样式
- leetcode 8(week 13)
- c#为什么叫csharp(因为C/C++在先,就起名字为“C++++”,即4个加号,为了简单,就写成了“C#”,这个解释有意思)