winRarファイルの解凍、圧縮
2193 ワード
package rar;
import java.util.Date;
/**
* winRar 、
* @author -wisdomLee
* @company
* @date Jan 7, 2013
*/
public class RarUtil {
/**
* @param args
*/
public static void main(String[] args) {
String path = "C:\\Program Files (x86)\\WinRAR\\";
String fileFrom = "D:/bcpFile/";
String fileTo = "D:/bcpFileRaR.rar";
winRar(path,fileFrom,fileTo);
}
/**
*
*
* @param path
* WinRaR.exe
* @param fileFrom
*
* @param fileTo
*
* @return
*/
public static boolean winRar(String path,String fileFrom,String fileTo){
boolean b = false;
Runtime rt = Runtime.getRuntime();
Process p = null;
int exitVal;
try{
p = rt.exec(path+"WinRaR.exe a -ep1 -r- -ibck -o+ "+fileTo+" "+fileFrom);//
exitVal = p.waitFor();
if (exitVal == 0) {
System.out.println(" !");
}
}catch (Exception e) {
System.out.println(new Date()+", :"+e.getMessage());
}finally{
p.destroy();
rt.freeMemory();
}
return b;
}
/**
*
*
* @param path
* WinRaR.exe
* @param fileFrom
*
* @param fileTo
*
* @return
*/
public static boolean unWinRar(String path,String fileFrom,String fileTo){
boolean b = false;
Runtime rt = Runtime.getRuntime();
Process p = null;
int exitVal;
try{
p = rt.exec(path+"WinRaR.exe x -ibck -y -o+ "+fileFrom+" "+fileTo);//
exitVal = p.waitFor();
if (exitVal == 0) {
System.out.println(" !");
}
}catch (Exception e) {
System.out.println(new Date()+", :"+e.getMessage());
}finally{
p.destroy();
rt.freeMemory();
}
return b;
}
}