Encontrar y abrir cualquier archivo .exe en C:/

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!

preguntado el 12 de febrero de 14 a las 08:02

Sí. Process process = Runtime.getRuntime().exec("Dummy.exe"); -

You need to recursively search the file tree from the start (/) to find your program, this is exactly what Files.walkFileTree está diseñado para hacer. -

2 Respuestas

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

Ejecuta el comando de cadena especificado en un proceso separado con el entorno y el directorio de trabajo especificados.

comando es la ubicación del .exe

envp puede ser nulo

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");

Respondido 12 Feb 14, 08:02

 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: busque archivos .txt en la carpeta especificada

contestado el 23 de mayo de 17 a las 13:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.