Home‎ > ‎Applied Core Java‎ > ‎Introduction‎ > ‎

MySystem

Problem : How to start notepad from a java program?

Step 1
- CODING
Create a text file c:\sunilos\MySystem.java  and copy below contents

/*

 */

public class MySystem {
   
    /**
     * Launch and native application notepad.exe
     * @param args
     * @throws Exception
     */
   
    public static void main(String[] args)throws Exception{
        Runtime.getRuntime().exec("notepad.exe");
    }

}

Step 2 - DEPLOYMENT
  1. Create a folder 'c:\sunilos'. 
  2. Create or copy MySystem.java  into 'c:\sunilos' folder.
  3. Open your command prompt and go to  'c:\sunilos'
  4. Compile MySystem.java with help of javac MySystem.java command.  Compiled class file will be created in  .\sunilos\MySystem.class folder
  5. Congratulations!! your Java program is ready to serve.
Step 3 - Testing
  1. Make sure you are on Command Prompt under c:\sunilos directory
  2. Now start your java program from command prompt with help of 
    • java MySystem command.
Output

It will open Notepad


<<Previous | Next>>
ċ
MySystem.java
(0k)
nakul shukla,
Mar 19, 2009, 7:53 AM
Comments