unrar.jar解壓縮rar文件

依賴的jar包 java-unrar-0.3.jarjava

在maven倉庫中,http://mvnrepository.com/artifact/com.github.junrar/junrar/0.7git

import java.io.File;github

import java.io.FileOutputStream;maven

import java.io.IOException;spa


import de.innosystec.unrar.Archive;.net

import de.innosystec.unrar.exception.RarException;ip

import de.innosystec.unrar.rarfile.FileHeader;get


public class UnRAR {it


/**io

* @param  args

* @throws  IOException 

* @throws  RarException 

*/

public static void main(String[] args) throws RarException, IOException {

//壓縮文件

String rarPath = "E:\\zip.rar";

//解壓到這個目錄

String dstDirectoryPath = "E:\\11";

File dstDiretory = new File(dstDirectoryPath); 

        if (!dstDiretory.exists()) {

        dstDiretory.mkdirs();             

        }

Archive a = new Archive(new File(rarPath));                

if (a != null) {  

a.getMainHeader().print(); //打印文件信息.                    

FileHeader fh = a.nextFileHeader();                     

while (fh != null) {                              

//文件                                  

File out = new File(dstDirectoryPath + File.separator + fh.getFileNameString().trim());

System.out.println(out.getAbsolutePath());                                 

FileOutputStream os = new FileOutputStream(out);                                     

a.extractFile(fh, os);                                     

os.close();

fh = a.nextFileHeader();

}

}

a.close();

}


}

相關文章
相關標籤/搜索