-2

I'm writing a program that needs to extract a zip file. I have code that should work, but for some reason throws a java.io.FileNotFoundException.

Here is the method:

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");
}

This produces the following console output:

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)
user207421
  • 305,947
  • 44
  • 307
  • 483
smithb99
  • 1
  • 1
  • 3
  • 2
    So where's `unzipMods` and `installServer`? In fact, where's `ServerInstaller`? The code snippet you've provided doesn't seem to relate to the error you're getting... – MadProgrammer Mar 22 '15 at 23:32
  • Do you need a clue? Look somewhere around `ServerInstaller` line 330. – hfontanez Mar 23 '15 at 03:40

1 Answers1

2

Why is BufferedOutputStream looking for META-INF/MANIFEST.MF?

It isn't. See the stack trace. new FileOutputStream(...) is looking for it.

Why? Because

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

encounters that path, which is returned by entry.getName().

user207421
  • 305,947
  • 44
  • 307
  • 483
  • The file doesn't exist. The only things in the zip file are JAR files. If I understand correctly, each `ZipEntry` is a file in the zip archive. The only entries are JAR files. There is no META-INF folder. – smithb99 Mar 24 '15 at 01:02