JAVA Runtime class and exec () method, use of Process

Source: Internet
Author: User

Package ioTest. io1;/** Runtime: each Java application has a Runtime class instance, so that the application can be connected to the running environment. * This is also an important reason for jvm to implement cross-platform. * You can use the getRuntime method to obtain the current runtime. * API analysis: * public class Runtime extends Object * each Java application has a Runtime class instance so that the application can be connected to the running environment. * You can use the getRuntime method to obtain the current runtime. * Applications cannot create their own Runtime class instances. ** the APIS found that there are no constructors, but there are non-static methods, then there must be a static method to get the Runtime Instance Object * getRuntime () and return the Runtime objects related to the current Java application. * **/Public class RuntimeDemo {public static void main (String [] args) throws Exception {Runtime runtime = Runtime. getRuntime (); // execute the command to start the console to enter the command and execute it. // You can use a Java program to start any file in a Java program. Process process=runtime.exe c ("D: \ app \ Xmp \ Program \ XMP.exe");/** exec () returns the Process Class Object * Process class: except constructors, the rest are abstract methods, which should have been implemented for subclasses. * However, the Process class is not subclass. In fact, when calling the above method, the system resource * is called to create an instance of this class. * // Thread. sleep (4000); process. destroy (); // you cannot end a process that is not started by the preceding method, because you cannot obtain the corresponding object. // Easy to use. runtime.exe c ("notepad.exe C: \ Users \ Leon \ New folder \ ioTest \ src \ ioTest \ io1 \ RuntimeDemo. java "); // question: how to solve the above problem with relative paths ?}}

Related Article

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.