日期:2014-05-17  浏览次数:20762 次

windows 下java调用winrar压缩文件为rar 格式

windows? 下java调用winrar压缩文件为rar 格式

?

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class RARFileRun {

	/**
	 * @param args
	 * @throws InterruptedException 
	 */
	public static void main(String[] args) throws InterruptedException , IOException, InterruptedException{
		String str="testrun.bat \"test rar file-2.xls\"";
		Process process=Runtime.getRuntime().exec(str);
		
		BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream(), "GBK"));
		 String line;   
		  while ((line = br.readLine()) != null) {   
		   System.out.println(line);
		  }  
		  br = new BufferedReader(new InputStreamReader(process.getErrorStream(), "gbk"));   
		  while ((line = br.readLine()) != null) {   
		    //System.err.println(line);   
		  }   
		  //等待子进程完成再往下执行。 
  
		  process.waitFor(); 
		System.out.println("OK");
	}

}

?

?

?

?

?

set b=%1%
set a=%~dp0
cd %a%
"C:\Program Files\WinRAR\WinRAR" a %a%%b%.rar %b%

?

1 楼 keshuangjie 2012-03-23  
大哥,java调用winrar压缩文件夹怎么搞,最近做个项目要用到,看到了就回复就回复一个哈