Automation Using Selenium Webdriver

Wednesday, 21 December 2016

How to open notepad using java program



  • Notepad is a text editor from windows operating system. We use notepad for writing text files.
  • We can open a new notepad using java code.
  • By using the concept of running another application by Runtime class in java.
  • By creating object of runtime and calling  exec() method by passing application name.
  • Lets see how to open a notepad using java code
  • OutPut::


  • Program #1: Java example program to open notepad


    1. package interestingJavaprograms;
    2. import java.io.IOException;
    3.  
    4. public class NotepadJava {
    5.  
    6.     /**
    7.      * @ www.corejavawithselenium.blogspot.in
    8.      * @ how to open a new notepad using java program
    9.      */
    10. public static void main(String[] args) {
    11.        
    12.           Runtime rt = Runtime.getRuntime();
    13.           
    14. try {
    15.       rt.exec("notepad");
    16. }
    17.  catch (IOException ex) {
    18.  
    19.  System.out.println(ex);
    20.  
    21. }  
    22.  
    23. }
    24.  
    25. }
  • OUPUT::