JAVA 调用外部安装7-Zip压缩和解压.zip文件时如何获取当前的进度?

坑;JAVA 调用外部安装7-Zip压缩和解压.zip文件时如何获取当前的进度?

Code

public static void unZip(String filename) throws Exception {
        File zipFile = new File(filename);
        if (!zipFile.exists()) {
            return;
        } 
        File zipExeFile = new File("./7z.exe");
        String exec = String.format("%s x -aoa \"%s\" -o\"%s\"", zipExeFile.getAbsolutePath(), zipFile.getAbsolutePath(), zipFile.getParent());
        Runtime runtime = Runtime.getRuntime();
        runtime.exec(exec);
    }
public static void zip(String srcRootPath,String zipFile) {
		String cmd = "7z a -tzip " + zipFile +  " " + srcRootPath;
		try {
			Runtime.getRuntime().exec(cmd);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

如何才能获取Runtime的执行状态?

posted @ 2019-08-26 10:05  bH1pJ  阅读(97)  评论(0编辑  收藏  举报