JAvaはrar圧縮と解凍を実現する


public class RarToFile {

	/*  
	 * cmd           
	 */
	private static String rarCmd = "C:\\Program Files\\WinRAR\\Rar.exe a ";
	private static String unrarCmd = "C:\\Program Files\\WinRAR\\UnRar x ";

	public static void main(String[] args) throws Exception {
		RARFile("RARRemote", "E:\\RemoteXml.xml", "E:\\");
	}

	/**  
	 *  1      RAR    
	 * rarName          (     )  
	 * fileName         (      )  
	 * destDir               
	 */
	public static void RARFile(String rarName, String fileName, String destDir) {
		rarCmd += destDir + rarName + ".rar " + fileName;
		try {
			Runtime rt = Runtime.getRuntime();
			Process p = rt.exec(rarCmd);
			if (p.waitFor() == 0) {
				System.out.println("    ");
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}

	/**  
	 *  1 RAR      
	 * rarFileName      RAR  (            )  
	 * destDir             
	 */
	public static void unRARFile(String rarFileName, String destDir) {
		unrarCmd += rarFileName + " " + destDir;
		try {
			Runtime rt = Runtime.getRuntime();
			Process p = rt.exec(unrarCmd);
			if (p.waitFor() == 0) {
				System.out.println("    ");
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}

}