<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Java – 創建受密碼保護的 Zip 文件 > 原文: [https://howtodoinjava.com/java/io/how-to-create-password-protected-zip-files-in-java/](https://howtodoinjava.com/java/io/how-to-create-password-protected-zip-files-in-java/) 本教程介紹**使用非常有用的庫 Zip4j 創建受密碼保護的 zip 文件**。 Java 默認情況下不提供文件密碼保護的任何支持。 盡管它對創建/提取 zip 文件具有很好的 API 支持。 還有一些其他有用的庫,它們同樣好,有時甚至比 zip4j 更好,但是它們也使用一些本機代碼,這使得它們的使用平臺在某種程度上依賴于。 **Zip4j 完全使用 Java 代碼,沒有任何本機代碼**的支持,因此它更適合我。 Zip4j 提供以下特性: * 創建,添加,提取,更新,從 Zip 文件中刪除文件 * 讀/寫受密碼保護的 Zip 文件 * 支持 AES 128/256 加密 * 支持標準 Zip 加密 * 支持 Zip64 格式 * 支持存儲(無壓縮)和壓縮壓縮方法 * 從分卷 Zip 文件創建或提取文件(例如:z01,z02,…zip) * 支持 Unicode 文件名 * 進度監視器 ## 1)下載 Zip4j 庫并將其包含到項目中 要下載 Zip4j 庫,請轉到其 [zip4j 下載頁面](http://www.lingala.net/zip4j/download.php)并下載其最新版本(直到今天的`zip4j_1.3.2.jar`)。 將`zip4j.jar`文件添加到您項目的類路徑中。 ## 2)創建受密碼保護的 zip 文件的示例 現在,您可以使用以下代碼創建受密碼保護的存檔。 您將需要使用 Java 6 來運行示例。 ```java import java.io.File; import java.util.ArrayList; import net.lingala.zip4j.core.ZipFile; import net.lingala.zip4j.exception.ZipException; import net.lingala.zip4j.model.ZipParameters; import net.lingala.zip4j.util.Zip4jConstants; public class CreatePasswordProtectedZipExample { public static void main(String[] args) { try { //This is name and path of zip file to be created ZipFile zipFile = new ZipFile("C:/temp/test.zip"); //Add files to be archived into zip file ArrayList<File> filesToAdd = new ArrayList<File>(); filesToAdd.add(new File("C:/temp/test1.txt")); filesToAdd.add(new File("C:/temp/test2.txt")); //Initiate Zip Parameters which define various properties ZipParameters parameters = new ZipParameters(); parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE); // set compression method to deflate compression //DEFLATE_LEVEL_FASTEST - Lowest compression level but higher speed of compression //DEFLATE_LEVEL_FAST - Low compression level but higher speed of compression //DEFLATE_LEVEL_NORMAL - Optimal balance between compression level/speed //DEFLATE_LEVEL_MAXIMUM - High compression level with a compromise of speed //DEFLATE_LEVEL_ULTRA - Highest compression level but low speed parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL); //Set the encryption flag to true parameters.setEncryptFiles(true); //Set the encryption method to AES Zip Encryption parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES); //AES_STRENGTH_128 - For both encryption and decryption //AES_STRENGTH_192 - For decryption only //AES_STRENGTH_256 - For both encryption and decryption //Key strength 192 cannot be used for encryption. But if a zip file already has a //file encrypted with key strength of 192, then Zip4j can decrypt this file parameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256); //Set password parameters.setPassword("howtodoinjava"); //Now add files to the zip file zipFile.addFiles(filesToAdd, parameters); } catch (ZipException e) { e.printStackTrace(); } } } ``` 還有其他有用的用例,您也可以查看其源碼發行版[**`zip4j_examples_eclipse_1.3.2.zip`**](http://www.lingala.net/zip4j/includes/downloadzip4j.php?option=examples&fmt=eclipse&jre=1.4)。 簽出這個非常有用的庫。 **祝您學習愉快!** 參考: [http://www.lingala.net/zip4j/](http://www.lingala.net/zip4j/)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看