How To Open Notepad in Java

Sharing is healthy !!

In this post we are going to show you how to open notepad in java.

To start with notepad is a text editor in Windows operating system, used in creating and editing text files. Notepad is also used in developing and editing java programs.

Here, i am going to show code implementation first and then explain what the code does.. So let’s see example,

example: How To Open Notepad in Java

Read also – How To Add Sitemap Link In WordPress Website

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

public class Open_Notepad_Java {

public static void main(String[] args) {

Runtime rt = Runtime.getRuntime();

try
{
rt.exec("Notepad");
}

catch(IOException ioe)
{
System.out.println(ioe);
}
}
}

Output:

How To Open Notepad in Java

Here in the above example the method getRuntime() is used to get reference of Runtime object. The exec method can also accept to open existing notepad file, like, exec(“flowerbrackets.txt”). If the notepad file does not exist then user will be prompted(dialog box will appear) to create a new notepad file. The above example is not restricted to open only notepad, rather you can open other applications like calculator.

Sharing is healthy !!

Leave a Reply

Your email address will not be published.