Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q4083 How would you execute a file from within a Java file?

irt.org | Knowledge Base | Java | Q4083 [ previous next ]

Q4083 How would you execute a file from within a Java file?

Check out the java.lang.Runtime class that provide access to the Java runtime system. This class has various methods that helps to implement system level services.

Here is a sample code which starts the notpad.

import java.lang.System;
import java.lang.Runtime;
import java.io.IOException;
public class loadNotepad
{
public static void main(String args[]) throws IOException 
        {
        Runtime load = Runtime.getRuntime();
        // getRuntime() method is a static method which is used to 
        // obtain access to an object of class Runtime.
        r.exec("C:\\windows\\notpad.exe");
        }
} // End of class loadNotpad

Feedback on 'Q4083 How would you execute a file from within a Java file?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.