猿问

Java中受密码保护的zip文件 问问题

我已经使用Java创建了zip文件,如下所示


import java.io.*;

import java.util.zip.*;


public class ZipCreateExample {

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

    System.out.print("Please enter file name to zip : ");

    BufferedReader input = new BufferedReader

        (new InputStreamReader(System.in));

    String filesToZip = input.readLine();

    File f = new File(filesToZip);

    if(!f.exists()) {

      System.out.println("File not found.");

      System.exit(0);

    }

    System.out.print("Please enter zip file name : ");

    String zipFileName = input.readLine();

    if (!zipFileName.endsWith(".zip"))

      zipFileName = zipFileName + ".zip";

    byte[] buffer = new byte[18024];

    try {

      ZipOutputStream out = new ZipOutputStream

          (new FileOutputStream(zipFileName));

      out.setLevel(Deflater.DEFAULT_COMPRESSION);

      FileInputStream in = new FileInputStream(filesToZip);

      out.putNextEntry(new ZipEntry(filesToZip));

      int len;

      while ((len = in.read(buffer)) > 0) {

        out.write(buffer, 0, len);

      }

      out.closeEntry();

      in.close();

      out.close();

    } catch (IllegalArgumentException iae) {

      iae.printStackTrace();

      System.exit(0);

    } catch (FileNotFoundException fnfe) {

      fnfe.printStackTrace();

      System.exit(0);

    } catch (IOException ioe) {

      ioe.printStackTrace();

      System.exit(0);

    }

  }

}

现在,当我单击zip文件时,它应该提示我输入密码,然后解压缩该zip文件。请任何帮助,我应该怎么走?


慕尼黑的夜晚无繁华
浏览 605回答 3
3回答
随时随地看视频慕课网APP

相关分类

Java
我要回答