有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

导出后的java FileSystemNotFoundException

今天我在出口后遇到了一个问题(我使用的是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();
    }
}

共 (2) 个答案

  1. # 1 楼答案

    我解决了这个问题,谢谢你的帮助

    我用过:

    &13;
    URI uri = getClass().getResource("myresourcefile.txt").toURI();
    
    if("jar".equals(uri.getScheme())){
        for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
            if (provider.getScheme().equalsIgnoreCase("jar")) {
                try {
                    provider.getFileSystem(uri);
                } catch (FileSystemNotFoundException e) {
                    // in this case we need to initialize it first:
                    provider.newFileSystem(uri, Collections.emptyMap());
                }
            }
        }
    }
    Path source = Paths.get(uri);
  2. # 2 楼答案

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

    与其试图将资源视为路径,不如将其作为InputStream获取,然后复制该InputStream:

    Path bleu = Paths.get("C:\\temp\\Bleu.exe");
    
    try (InputStream source = Bleu.class.getResourceAsStream("Bleu.exe")) {
        Files.copy(source, bleu);
    }