为什么BufferedOutputStream正在寻找META-INF / MANIFEST.MF?

时间:2015-03-22 23:30:40

标签: java java-io fileoutputstream meta-inf

我正在编写一个需要提取zip文件的程序。我的代码应该可以使用,但出于某种原因抛出java.io.FileNotFoundException

以下是方法:

private static void unzip() {
    ZipInputStream input = null;
    try {
        input = new ZipInputStream(new BufferedInputStream(new FileInputStream(SERVER_FOLDER + File.separator + "folder" + File.separator + "mods.zip")));
    } catch (FileNotFoundException e) {
        System.err.println("The program has encountered an error and needs to stop.\nPlease notify the program author of this problem.");
        e.printStackTrace();
        System.exit(-1);
    }

    ZipEntry entry;
    final int BUFFER = 8192;

    System.out.print("Extracting...");

    try {
        byte[] data = new byte[BUFFER];
        while ((entry = input.getNextEntry()) != null) {
            BufferedOutputStream output = new BufferedOutputStream(
                    new FileOutputStream(entry.getName()), BUFFER);
            int count;
            while ((count = input.read(data, 0, BUFFER)) != -1) {
                output.write(data, 0, BUFFER);
            }
            input.closeEntry();
            output.flush();
            output.close();
        }
        input.close();
    } catch (IOException e) {
        System.err.println("The installer has encountered an error and needs to stop.\nPlease notify the program author of this problem.");
        e.printStackTrace();
        System.exit(-1);
    }
    System.out.println("Done");
}

这会产生以下控制台输出:

java.io.FileNotFoundException: META-INF/MANIFEST.MF (No such file or directory)
    at java.io.FileOutputStream.open(Native Method)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:101)
    at me.smithb99.installer.ServerInstaller.unzipMods(ServerInstaller.java:330)
    at me.smithb99.installer.ServerInstaller.installServer(ServerInstaller.java:84)
    at me.smithb99.installer.Main.main(Main.java:71)

1 个答案:

答案 0 :(得分:2)

  

为什么BufferedOutputStream正在寻找META-INF / MANIFEST.MF?

不是。查看堆栈跟踪。 new FileOutputStream(...)正在寻找它。

为什么呢?因为

new FileOutputStream(entry.getName()), BUFFER)

遇到entry.getName().

返回的路径