【问题标题】:Fixing broken zip file by using ProcessBuilder使用 ProcessBuilder 修复损坏的 zip 文件
【发布时间】:2019-07-04 05:31:07
【问题描述】:

当我在我的 Mac 终端中执行“zip -FF /Users/myZip.zip?--out Users/myFixed.zip”时,损坏的 zip 文件已修复。 当我尝试修复与下面相同的损坏的 zip 文件时,它给了我以下错误。

请分享您的意见以解决此问题。

代码:

ProcessBuilder pb1 = new ProcessBuilder("bash", "-c", "zip -FF/Users/myZip.zip 
   --out /Users/myFixed.zip");
   pb1.redirectErrorStream(true);
   Process p =pb1.start();

错误信息:

1 Fix archive (-FF) - salvage what can
2   zip warning: could not open input archive: /Users/myZip.zip
3 Scanning for entries... 
4  Could not find: /Users/myZip.z01
5
6 
7 Hit c      (change path to where this split file is)
8     s      (skip this split)
9     q      (abort archive - quit)
10    e      (end this archive - no more splits)
11    z      (look for .zip split - the last split)

【问题讨论】:

  • zip warning: could not open input archive: /Users/myZip.zip - 我想该文件实际上低于/Users/<username>/
  • 无论我把 (/Users// or /Users//Desktop/) 损坏的文件放在哪里,我都只能修复损坏的文件通过zip -FF broken.zip --out fixed.zip 命令在mac 终端中,但它在我的程序中不起作用@ScaryWombat
  • 看下面的答案

标签: java zip corrupt


【解决方案1】:

每个参数应该是不同的字符串

例如

ProcessBuilder pb1 = new ProcessBuilder("bash", "-c", "zip", "-FF", "/Users/myZip.zip", 
   "--out", "/Users/myFixed.zip");

【讨论】:

  • 我试过了,但我得到了相同的结果。即使尝试使用 apache commons exec String line = "bash -c zip -FF /Users/<username>/myZip.zip --out /Users/<username>/myFixed.zip"; CommandLine cmdLine = CommandLine.parse(line); System.out.println(cmdLine.toString()); Executor executer = new DefaultExecutor(); executer.execute(cmdLine); executer.setExitValue(1); 但仍然是同样的错误!@ScaryWombat
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-03-01
  • 2014-08-06
  • 2020-12-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多