2.Java Base Runtime Object

Source: Internet
Author: User

Bi Xiangdong Teacher Java Basic Learning Note--runtime Object

After learning the runtime object in Java today, it is important for us to have the following useful objects.

1. Use Java code to open a local executable file, such as opening a calculator.

2. Open a program and use the program to open a supported file.

For example: 1. Open Notepad, open the *.java file with Notepad,

2. Open the Storm audio player and open a local video with the player.

The sample code is as follows:

/************************************** Runtime object: 1. The class does not provide a constructor function.   The description cannot be a new object, then the methods in the class are directly thought to be static.     2. There is also a non-static method in this class stating that the class will certainly provide a way to get this class of object, and that the method is static, and that the return value type is of this class type. It can be seen from this feature that the class is completed using a singleton design pattern. The mode four static Runtime getruntime ();*/classruntimedemo{ Public Static voidMain (string[] args)throwsException {Runtime R=Runtime.getruntime (); Process P=r.exec ("Calc.exe");//Open Calculator Executable programThread.Sleep (4000);//process Hibernation 4000 msP.destroy ();//Kill the Calc.exe process, and note that you can only kill the process you have set up, not to kill the process that has been established. Process P2=r.exec ("notepad.exe D:/runtimedemo.java");//Open a Notepad program and open any type of file supported by Notepad.     }}

Program:

2.Java Base Runtime Object

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.