Java program to open Notepad

Created with Sketch.

 

Java program to open Notepad

Java program to open Notepad, it’s a text editor installed in the Windows operating system and used for creating and editing text files. You may be writing Java programs in it, but you can also open it from your Java program.

How to open Notepad using Java program?

import java.util.*;
import java.io.*;

class Notepad {
public static void main(String[] args) {
Runtime rs = Runtime.getRuntime();

try {
rs.exec(“notepad”);
}
catch (IOException e) {
System.out.println(e);
}
}
}

 

Method getRunTime is used to get the reference of the current RunTime object. The exec method can be used to execute commands. You can also specify a file while opening Notepad, such as exec(“notepad programming.txt”), where ‘programming.txt’ is the file you wish to open. If the file doesn’t exist in the current working directory, then a dialog box is displayed to create a file.

You can launch other applications using the exec method. For example, exec(“calc”) launches the calculator application. If an application is present in a directory that isn’t set in environment variable PATH, then you can specify the complete path of the application.

If you are still using Notepad for Java development, it’s recommended to switch to some advanced text editor like Notepad++ or use a development IDE.

Leave a Reply

Your email address will not be published. Required fields are marked *