Compress with zip command of java side linux
        
      
      
   
      
If you want to call the zip command of linux on the java side, you can use ProcessBuilder.
Example 1:
If you keep all directories
List commandList = new ArrayList();
commandList.add("-r");
ProcessBuilder pb =new ProcessBuilder(commandList);
Example 2:
If the directory is not retained (error if the same file name is used)
List commandList = new ArrayList();
commandList.add("-j");
ProcessBuilder pb =new ProcessBuilder(commandList);
LINUX zip command list
-f   freshen: only changed files
-u   update: only changed or new files
-d   delete entries in zipfile
-m   move into zipfile (delete OS files)
-r   recurse into directories
-j   junk (don't record) directory names
-0   store only
-l   convert LF to CR LF (-ll CR LF to LF)
-1   compress faster
-9   compress better
-q   quiet operation
-v   verbose operation/print version info
-c   add one-line comments
-z   add zipfile comment
-@   read names from stdin
-o   make zipfile as old as latest entry
-x   exclude the following names
-i   include only the following names
-F   fix zipfile (-FF try harder)
-D   do not add directory entries
-A   adjust self-extracting exe
-J   junk zipfile prefix (unzipsfx)
-T   test zipfile integrity
-X   eXclude eXtra file attributes
-y   store symbolic links as the link instead of the referenced file
-e   encrypt
-n   don't compress these suffixes
Example 3 What to do in the following cases?
Folder format: / home / AB / CD / + Various files and subfolders
Input perspective
/home/AB/CD/
After compression (/ home / AB / CD / not included)
各種ファイルとサブフォルダ.zip
Try it, the command below is good.
pb = new ProcessBuilder("sh", "-c", “zip -r test.zip ./*”)).directory(new File("/home/AB/CD/"));
You can also write in the same way.
pb = new ProcessBuilder("/bin/sh", "-c", “zip -r test.zip ./*”)).directory(new File("/home/AB/CD/"));
pb = new ProcessBuilder("/bin/bash", "-c", “zip -r test.zip ./*”)).directory(new File("/home/AB/CD/"));