Zip4j 压缩包加密压缩与解压
生活随笔
收集整理的這篇文章主要介紹了
Zip4j 压缩包加密压缩与解压
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
引入依賴:zip4j
<dependency><groupId>net.lingala.zip4j</groupId><artifactId>zip4j</artifactId><version>1.3.2</version> </dependency>一、壓縮
不多說直接上圖,如下圖為我測(cè)試的文件路徑。
桌面上的“測(cè)試加密壓縮”文件夾下,一個(gè)為文件,一個(gè)為文件夾。
壓縮后效果圖:
成功加密壓縮。
二、解壓
解壓就比較簡(jiǎn)單了,路徑對(duì)就沒問題了
public class Test {public static void main(String[] args) throws Exception { // compressedFileWithPassword("C:/Users/12495/Desktop/測(cè)試加密壓縮", // "C:/Users/12495/Desktop/測(cè)試加密壓縮","123456");zipUncompressPassword("C:/Users/12495/Desktop/測(cè)試加密壓縮.zip", "123456");}/*** 解壓縮* @param inputFile 壓縮包的路徑* @throws Exception*/public static void zipUncompressPassword(String inputFile, String password) throws Exception {File file = new File(inputFile);ZipFile zipFile = new ZipFile(file);//設(shè)置文件編碼,根據(jù)實(shí)際場(chǎng)景zipFile.setFileNameCharset("GBK");if (zipFile.isEncrypted()) {zipFile.setPassword(password.toCharArray());}zipFile.extractAll(inputFile.replace(".zip", ""));} }以上就是解壓的過程。
總結(jié)
以上是生活随笔為你收集整理的Zip4j 压缩包加密压缩与解压的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux下 eclipse下载
- 下一篇: 软件保护概述