Archive -------------------------------------------------------------------------------------------
StringBuilder dittoCommand = new StringBuilder();
dittoCommand.append("ditto -cj --keepParent ");
dittoCommand.append(sourceDirOrFile);
dittoCommand.append("' '");
dittoCommand.append(pathToEncodedFile);
dittoCommand.append("'");
String[] cmd = {"/bin/sh", "-c", dittoCommand.toString()};
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(cmd);
//Consume the standard error stream of this process.
StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR", true);
//Consume the standard input stream of this process.
StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT");
// kick them off
errorGobbler.start();
outputGobbler.start();
// any error???
int exitVal = proc.waitFor();
//Give the stream gobblers time to handle the remaining contents in the streams.
Thread.yield();
proc.destroy();
}
catch (Exception e)
{
e.printStackTrace();
}
Unarchive -----------------------------------------------------------------------
try