【发布时间】:2016-11-18 20:56:18
【问题描述】:
我试图将一个 exe 文件包含到一个 jar 应用程序中并运行它。这个想法是首先将其临时提取,然后运行 temp-exe 文件。怎么做?这就是我所尝试的。有我的代码。由于源文件“ffmpeg.exe”而发生异常java.io.FileNotFoundException。我验证了,但是文件包含,目录是正确的。
package extractffmpeg;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.stage.Stage;
import org.apache.commons.io.FileUtils;
public class ExtractFFmpeg extends Application {
public void start(Stage primaryStage) throws IOException, URISyntaxException {
extractExe();
System.out.println("extract successfull");
Platform.exit();
}
public static void main(String[] args) {
launch(args);
}
public void extractExe() throws URISyntaxException, IOException{
final String resourcesPath = "ffmpeg/ffmpeg.exe";
URL url = ExtractFFmpeg.class.getResource(resourcesPath);
File source = new File(url.toString());
System.out.println("shows url of ffmpeg: " + url.getPath());
System.out.println("shows file of ffmpeg: " + source);
File destination = new File("C:/Users/FNI2Abt/Desktop/ffmpeg.exe");
FileUtils.copyFile(source, destination);
}
}
【问题讨论】:
-
使用getResourceAsStream 并编写一个方法,该方法从资源流中重复读取缓冲区,然后将其写入目标直到EOF。