HOW TO OPEN EXECUTABLE (.EXE) APPLICATION USING JAVA?

In this blog, I am going to explain about "How to open executable (.exe) application using java?". We will learn to open .exe file using Java and later you can use this to run any .exe file for future programs.



Below is the example Java program to open Notepad.exe file from the system.



Java Source code:

package com.helloselenium.selenium.test;

import java.io.IOException;

public class OpenExeFile{

  try {
      Runtime runtime = Runtime.getRuntime();
      runtime.exec("C:\\Windows\\System32\\Notepad.exe");
   
   } catch (IOException e1) {
      e1.printStackTrace();
   } 

}

Below are the line by line code explanation for above Java program:




package com.helloselenium.selenium.test;
Above code is package structure for current program file.
Following code is the required packages to handle Java IOException.
import java.io.IOException;
Following code is to define the runtime object.
Runtime runtime = Runtime.getRuntime();
Following code is to open Notepad.exe file. Here default path of Notepad.exe is used, you can replace it with your test exe file.
runtime.exec("C:\\Windows\\System32\\Notepad.exe");


Post a Comment

0 Comments