0

I am new to java (especially exceptions like IO, which might be my problem), and I am having trouble running a .exe file that is located inside a folder in my Java project (A gameboy emulator). Here's what I have so far:

try {
            Runtime.getRuntime ().exec ("\VBA\VisualBoyAdvance-1.8.0-511.exe");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

The folder that VisualBoyAdvance is in is called VBA, every time I run the program, it says that the .exe is not found. How should I be formatting this?

Tony S
  • 35
  • 4
  • are u running this on a mac or windows ? if its windows u need to have the drive name specified c: – user641887 Sep 01 '17 at 20:31
  • Possible duplicate of [Run .exe file from Java from file location](https://stackoverflow.com/questions/10685893/run-exe-file-from-java-from-file-location) – DimaSan Sep 01 '17 at 20:33

2 Answers2

0

if you are running on windows and the file is in C: drive then try something like this

try {
            Runtime.getRuntime ().exec ("c:\\VBA\\VisualBoyAdvance-1.8.0-511.exe");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
user641887
  • 1,506
  • 3
  • 32
  • 50
0

Since the folder with file is in project directory, you can get absolute path to your file, like this:

String path = new File("VBA/VisualBoyAdvance-1.8.0-511.exe").getAbsolutePath();

And then execute using this path:

Runtime.getRuntime().exec(path);
Anar Sultanov
  • 3,016
  • 2
  • 17
  • 27