0

I'm trying to create a small Java program that allows you to ask it to open an .exe file in a java window I created.

Here's a small example of what I want

User: Open chrome Program: starts looking for a file called chrome.exe in C:/ and opens it

And that for any .exe file.

Is there any way to achieve this in Java? Thanks!

user3231227
  • 67
  • 1
  • 8
  • Yes. `Process process = Runtime.getRuntime().exec("Dummy.exe");` – Maroun Feb 12 '14 at 08:06
  • You need to recursively search the file tree from the start (`/`) to find your program, this is exactly what [`Files.walkFileTree`](http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#walkFileTree(java.nio.file.Path,%20java.nio.file.FileVisitor)) is designed to do. – Boris the Spider Feb 12 '14 at 08:25

2 Answers2

2
exec(String command, String[] envp, File dir)

Executes the specified string command in a separate process with the specified environment and working directory.

command is the location of the .exe

envp can be null

dir is the directory of your .exe

With respect to your question it should be...

Runtime.getRuntime().exec("c:\\program files\\chrome\\chrome.exe", null, new File("c:\\program files\\chrome");
Sathesh
  • 378
  • 1
  • 4
  • 13
0
 Process p = Runtime.getRuntime().exec("cmd /c start "+file.getAbsolutePath());

how to run the exe file

and to find files(search) have a read at Java: Find .txt files in specified folder

Community
  • 1
  • 1
Daksh Shah
  • 2,997
  • 6
  • 37
  • 71