/* how to open notepad using java program, opening notepad in java code,how to open a text file in java with notepad, how to open notepad through java program */
public calss demo
{
public void note()
{
try {
System.out.print(".....Opening notepad.....");
java.lang.Runtime runTime = java.lang.Runtime.getRuntime();
java.lang.Process process = runTime.exec("notepad");
try {
//notepad will be closed after 5000 ms
java.lang.Thread.sleep(5000);
} catch (java.lang.InterruptedException e) {
e.printStackTrace();
}
System.out.println("Closing notepad");
process.destroy();
} catch (java.io.IOException e) {
e.printStackTrace();
}
}
}
public class notepad {
public static void main(String[] args) {
new demo().note();
}
}
How to run:
javac notepad.java
java notepad
Output:
public calss demo
{
public void note()
{
try {
System.out.print(".....Opening notepad.....");
java.lang.Runtime runTime = java.lang.Runtime.getRuntime();
java.lang.Process process = runTime.exec("notepad");
try {
//notepad will be closed after 5000 ms
java.lang.Thread.sleep(5000);
} catch (java.lang.InterruptedException e) {
e.printStackTrace();
}
System.out.println("Closing notepad");
process.destroy();
} catch (java.io.IOException e) {
e.printStackTrace();
}
}
}
public class notepad {
public static void main(String[] args) {
new demo().note();
}
}
How to run:
javac notepad.java
java notepad
Output: