-1

The JAR file consists of the ffmpeg.exe file and it can run normally on my machine without any problems. However, if I try to run it on another computer it would tell me that java.io.IOException: Cannot run program "ffmpeg.exe": CreateProcess error=2,The system cannot find the file specified from the stacktrace. The way I imported it was

FFMpeg ffmpeg = new FFMpeg("ffmpeg.exe");  //in res folder

...
//ffmpeg class
public FFMPEG(String ffmepgEXE) {
    this.ffmepgEXE = ffmepgEXE;
}
john pear
  • 3
  • 2
  • Is the res folder packaged inside the jar, or is it located in the same file as the jar? If it's inside the jar, then you need to load it as a resource, not `new FFMpeg("ffmpeg.exe");` which will attempt to lad the file from the working directory (same folder as the jar). – sorifiend Apr 22 '22 at 03:31
  • 1
    Does this answer your question? [Get a resource using getResource()](https://stackoverflow.com/questions/2593154/get-a-resource-using-getresource) – sorifiend Apr 22 '22 at 03:32
  • https://prnt.sc/6ms_rJqUv1tu the folder isn't there but all the files are. I tried changing the constructor to just `this.ffmepgEXE = getClass().getResource("/ffmpeg.exe").getPath();` but it's giving me the `The system cannot find the file specified` error when I try to use it – john pear Apr 22 '22 at 03:58

1 Answers1

1

The quick fix is you have to put ffmpeg.exe in the same folder with your .jar file.

If you want to read file from resources folder, you have to change this code:

URL resource = Test.class.getResource("ffmpeg.exe");
String filepath = Paths.get(resource.toURI()).toFile().getAbsolutePath(); 
FFMpeg ffmpeg = new FFMpeg(filepath);
Huka
  • 380
  • 2
  • 12
  • I'm trying to make it so that the other computer don't have access to the `ffmpeg.exe` file. I tried following that article but his dealt with readable files while I just want the file path for the `ffmpeg.exe` file – john pear Apr 22 '22 at 04:05
  • I updated the answer. Could you test it? – Huka Apr 22 '22 at 05:58
  • I'm getting a null pointer on line 3, even in my IDE – john pear Apr 22 '22 at 12:11