0

I modified some of the suggestions I found in this questions and this one to get the code snippet below, the challenge is that it runs without error, but does not extract the content of the release.zip, any pointers to what I am missing?

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

        /* Unzip the release */
        File folder = new File("./input/");
        ProcessBuilder pb = new ProcessBuilder(
                "C:/Program Files/7-Zip/7z.exe",
                "x",
                "./input/matsimInput/release.zip",
                "new");
        pb.directory(folder);
        pb.redirectErrorStream(true);

        Process pbProcess = null;
        int pbExitCode = 1;

            pbProcess = pb.start();
            pbExitCode = pbProcess.waitFor();

        if(pbExitCode != 0) {
            throw new RuntimeException("Could not unzip release for MATSim run");
        }

    }
Nobi
  • 1,113
  • 4
  • 23
  • 41
  • My I suggestion to use the built-in zipping algorithm instead. Invoking an external application is kinda crazy. Search for 'Java GZIP' or smth along the lines of that. – Marcel Sep 18 '18 at 21:32
  • +1 to use the Java ZIP / GZIP native capabilities to extract data from ZIP-archives. Otherwise you owe us an explanation why do you want to use external application and make your code platform (Windows) dependent? – Vladimir L. Sep 18 '18 at 21:51
  • 2
    Google gives a nice article as one of the first hits, just for you: https://www.baeldung.com/java-compress-and-uncompress – Vladimir L. Sep 18 '18 at 21:54
  • Since you're not actually reading the output of the process, how do you know if it's actually failing or not? – MadProgrammer Sep 18 '18 at 22:01

1 Answers1

0

Using 7-zip is one option. If you have java installed, you can use jar also. An example to modify the process builder command: ProcessBuilder pb = new ProcessBuilder("cmd.exe","/C", "jar", "-xf" "");

Here: -x means extraction and -f refers to the filename. This will extract the file in the current directory where you have your java program.