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