Java process - unable to unzip zip file

后端 未结 2 1943
梦毁少年i
梦毁少年i 2021-01-28 21:07

I am trying to unzip some zip file, it has about 65 megs. Code snippets below:

This method actually unzips a file:

public synchronized void execute(Path          


        
相关标签:
2条回答
  • 2021-01-28 21:17

    I think problem is because of timeout constraint.

    You can try below code to execute process

    Runtime runtime = Runtime.getRuntime();
    Process process = runtime.exec(commandLine);
    

    I think it will work.

    0 讨论(0)
  • 2021-01-28 21:27

    The unzip command prints the details of the files it is unzipping to its standard output, so you need to read this in your Java program (via Process.getInputStream). If you don't read the output in a timely fashion the process may block once its buffer gets full - this is spelled out in the javadoc of Process.

    I recommend you call builder.redirectErrorStream(true) and then ensure you read all the data from the process stream. You may also benefit from adding a -qq argument to the unzip call, to minimise the amount of output it creates in the first place.

    0 讨论(0)
提交回复
热议问题