Search code examples
javacommandzipepub

How to use zip command using Runtime().getRuntime().exec() except directory folders in JAVA?


I'm necessary to use zipping using unix command in JAVA.

But in JAVA, CD command can not be used I know.

Below code :

    String command = "zip -0Xq /Users/tmdtjq/Downloads/PDFTest/test/test.zip /Users/tmdtjq/Downloads/PDFTest/test/mimetype";

    Runtime rt = Runtime.getRuntime();

    rt.exec(command);

If I use above code, mimetype file is zipped with directory folder "/Users/tmdtjq/Downloads/PDFTest/test/".

But I want to zip just the mimetype file.

I can not use java Library about ZIP. because I try to make epub file, I have to use zip command "zip -0Xq" and "zip -Xr9Dq" for making epub3 file.

Could you suggest How to use zip command using exec() in JAVA except directory folders?

Or if there is other ways to zip in epub format, introduce Zip Library which is possible to zip mimetype to epub format?

this is zipping form using above code


Solution

  • If you use ProcessBuilder instead you can use directory to set you cwd instead.