【发布时间】:2012-05-13 12:48:09
【问题描述】:
我正在编写一个需要压缩文件的程序。 这将在 linux 和 windows 机器上运行。它在 Linux 中运行良好,但我无法在 Windows 中完成任何操作。 要发送命令,我正在使用 apache-net 项目。我也尝试过使用 Runtime().exec 但它不起作用。 有人可以提出一些建议吗?
CommandLine cmdLine = new CommandLine("zip");
cmdLine.addArgument("-r");
cmdLine.addArgument("documents.zip");
cmdLine.addArgument("documents");
DefaultExecutor exec = new DefaultExecutor();
ExecuteWatchdog dog = new ExecuteWatchdog(60*1000);
exec.setWorkingDirectory(new File("."));
exec.setWatchdog(dog);
int check =-1;
try {
check = exec.execute(cmdLine);
} catch (ExecuteException e) {
} catch (IOException e) {
}
【问题讨论】:
-
我们可以看看你的代码吗
-
您在 Windows 中使用的是什么 zip 程序?
-
当您发布代码时,请同时发布任何错误消息。