You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

69 lines
2.3 KiB

package com.insigma.utils;
import com.insigma.config.AppCfg;
import java.io.File;
/**
* (ZipUtil 类)
*
* @author zhangxianwei
* @since 17:34 2022/4/18
*/
public class ZipUtil {
private static final String SX = "/";
private static final String XX = "\\";
public static void zip7Z(String dirName, String zipFileName) {
if (XX.equals(File.separator)) {
String cmd7z = getRootPath() + "7-Zip/7z.exe";
try {
String cmd = "cmd.exe /c " + cmd7z.trim().replace(" ", "\" \"") + " a -tzip \"" + zipFileName + "\" \"" + dirName + "\\*\"";
new WinCommandUtil(cmd).run();
} catch (Exception ie) {
ie.printStackTrace();
}
} else if (SX.equals(File.separator)) {
try {
String cmd777 = "chmod -R 777 "+dirName;
new LinuxCommandUtil(cmd777).run();
int index = cmd777.lastIndexOf(File.separator);
String cmd777Short = cmd777.substring(0,index);
new LinuxCommandUtil(cmd777Short).run();
String cmd = "7z a "+zipFileName+" "+dirName+" ";
new LinuxCommandUtil(cmd).run();
} catch (Exception ie) {
ie.printStackTrace();
}
}
}
public static void unZip7Z(String filepath, String destinationDir) {
if (XX.equals(File.separator)) {
String cmd7z = getRootPath() + "7-Zip/7z.exe";
try {
String cmd = "cmd.exe /c " + cmd7z.trim().replace(" ", "\" \"") + " x \"" + filepath + "\" -o\"" + destinationDir + "\" " + " -y ";
new WinCommandUtil(cmd).run();
} catch (Exception ie) {
ie.printStackTrace();
}
} else if (SX.equals(File.separator)) {
try {
String cmd777 ="chmod -R 777 "+filepath+File.separator;
new WinCommandUtil(cmd777).run();
String cmd = "unzip -o "+filepath+" -d "+destinationDir+"";
new WinCommandUtil(cmd).run();
new WinCommandUtil(cmd777).run();
} catch (Exception ie) {
ie.printStackTrace();
}
}
}
public static String getRootPath() {
return AppCfg.HZB + "/tomcat8/webapps/qggwy/WEB-INF/classes/static/softTools/";
}
}