How to open notepad using java application
You can use java.lang.Runtime class to interact with Runtime Environment.
To create instance of Runtime class you can use getRuntime() method like
Runtime runtime = Runtime.getRuntime();
getRuntime() is a static factory method used to create object of Runtime class. You can not create object of Runtime class using new operator and constructor(new Runtime();) because constructor present in Runtime class is private.
There is one more method present in java.lang.Runtime class called exec() method. This method is used to executes the specified system command in a separate process. You can use this method to launch external applications like notepad, browser or any media player through your java program.
now java program to open notepad application.
To create instance of Runtime class you can use getRuntime() method like
Runtime runtime = Runtime.getRuntime();
getRuntime() is a static factory method used to create object of Runtime class. You can not create object of Runtime class using new operator and constructor(new Runtime();) because constructor present in Runtime class is private.
There is one more method present in java.lang.Runtime class called exec() method. This method is used to executes the specified system command in a separate process. You can use this method to launch external applications like notepad, browser or any media player through your java program.
now java program to open notepad application.
public class OpenNotepadTest { public static void main(String[] args) { Runtime runtime = Runtime.getRuntime(); try { runtime.exec("notepad.exe"); } catch (IOException e) { e.printStackTrace(); } } }
Comments
Post a Comment