使用unrar.jar解壓縮rar文件
依賴的jar包 java-unrar-0.3.jar
在maven倉庫中,http://mvnrepository.com/artifact/com.github.junrar/junrar/0.7
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import de.innosystec.unrar.Archive;
import de.innosystec.unrar.exception.RarException;
import de.innosystec.unrar.rarfile.FileHeader;
public class UnRAR {
/**
* @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();
}
} 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!