//压缩是通过命令来调用的,需要服务器安装rar
package com.gs.system.util.clear;
import com.gs.system.util.Config;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* Created by gj.hu on 2016/3/22.
*/
public class RARUtil {
/**
* @param
* @throws InterruptedException
* @throws IOException
* @throws IOException
* @throws InterruptedException
*/
public static int fileToRar(String aimpath,String realPath) throws Exception {
String rarPaht= Config.readConfig("rar_path");
StringBuffer cmd= new StringBuffer(rarPaht);//安装的winrar路径
cmd.append(" a -ep ");
cmd.append(aimpath);
cmd.append(" ");
cmd.append(realPath);
Process proc;
try {
proc = Runtime.getRuntime().exec(cmd.toString());
BufferedReader br = new BufferedReader(new InputStreamReader(proc.getInputStream(), "UTF-8"));
String line;
while ((line = br.readLine()) != null) {
//System.out.println(line);
}
br = new BufferedReader(new InputStreamReader(proc.getErrorStream(), "UTF-8"));
while ((line = br.readLine()) != null) {
//System.err.println(line);
}
// 当前线程等待该process结束,既挂起主线程
proc.waitFor();
return 1;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return 0;
}
}
public static void main(String[] args) throws Exception {
String aimpath="E:/7.rar ";
String realPath="E:/1/20160323/tar";
int dd=fileToRar(aimpath,realPath);
System.out.println("11");
System.out.println(dd);
}
}
java 压缩rar文件
最新推荐文章于 2023-07-20 14:24:28 发布