gpt4 book ai didi

java - 导出后出现 FileSystemNotFoundException

转载 作者:太空宇宙 更新时间:2023-11-04 09:27:22 27 4
gpt4 key购买 nike

今天我在导出后遇到问题(我使用的是 ecplise)(我的应用程序在导出之前有效,但在导出之后无效)

错误屏幕:https://image.noelshack.com/fichiers/2019/33/4/1565884882-capture.png

我尝试使用其他库处理选项导出,它给了我同样的错误,但有更多错误:

错误屏幕:https://image.noelshack.com/fichiers/2019/33/4/1565885180-capture.png

这是我的启动方法所在的类:

package com.bleu.application;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Bleu {

public static void launch() throws IOException, URISyntaxException {


File Bleu = new File("C:\\temp\\Bleu.exe");

URL url = Bleu.class.getResource("Bleu.exe");
Path source = Paths.get(url.toURI());

Files.copy(source, Bleu.toPath());

}
}

还有主类

package com.bleu;

import java.io.IOException;
import java.net.URISyntaxException;

import com.bleu.application.Bleu;
import com.bleu.bootstrap.bootstrap;

public class Main {

public static void main(String[] args) throws IOException, URISyntaxException {

Checker.deleteExists();

bootstrap.update();
Bleu.launch();
}
}

最佳答案

永远不要假设资源是常规文件。如果资源位于 .jar 文件内,则它只是压缩字节的子序列,而不是真正的文件。

不要尝试将资源视为路径,而是将其作为输入流获取,然后复制该输入流:

Path bleu = Paths.get("C:\\temp\\Bleu.exe");

try (InputStream source = Bleu.class.getResourceAsStream("Bleu.exe")) {
Files.copy(source, bleu);
}

关于java - 导出后出现 FileSystemNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57512801/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com