解压一个目录包括子目录中的所有 zip (包括套娃) 文件

解压一个目录包括子目录中的所有 zip (包括套娃)文件

package unzip;

import java.io.*;
import java.nio.charset.Charset;
import java.util.*;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

/**
 * @author jeffrey
 * @ClassName: UnZip
 * @Description: 为偷懒而生,解压一个目录包括子目录中的所有 zip 文件
 * @date: 2021/1/9 12:38 上午
 * @version:
 * @since JDK 1.8
 */


public class UnZip {
   

    /**
     * 用于存放于 zip 文件的安全队列
     */
    public final static ConcurrentLinkedQueue<File> ZIP_QUEUE = new ConcurrentLinkedQueue<>();

    /**
     * 如 t1 不存活并 zipQueue 为空则修改为 true
     */
    public static boolean isFlag = false;

    /**
     * 输入流
     */
    private static final Scanner SCANNER = new Scanner(System.in);

    /**
     * 提供一个工作路径
     */
    private static String workPath;

    /**
     * 在解压完成后是否删除源文件
     *      使用 Boolean 包装类进行判断,True / true 为 true,False / false 为 false,其他依然为 false
     */
    public static String isDelete;

    /**
     * 在解压文件时发生异常的集合
     *      Key:文件名
     *      Value:异常对象
     */
    public static final HashMap<File, Exception> unZipFailedMap = new HashMap<>();

    /**
     * 删除失败的文件名
     */
    public static final HashSet<File> deleteFailedNameList = new HashSet<>();

    /**
     * 找到相关的文件数量
     */
    public static int foundCount = 0;

    /**
     * 成功解压的文件数量
     */
    public static int succeedCount = 0;

    /**
     * 解压失败的文件数量
     */
    public static int unZipFailedCount = 0;

    /**
     * 删除失败的文件个数
     */
    public static int deleteFailedCount = 0;


    public static void main(String[] args) {
   

        input();

        if (new File(workPath).exists()) {
   

                Thread t1 = new Thread(new FindZipFile(new File(workPath)));
                Thread t2 = new Thread(new UnZipFile(ZIP_QUEUE));
                t2.setPriority(Thread.MAX_PRIORITY);

                t1.start();
                t2.start();

                while (true) {
   
                    if (!<
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
无限套字典的键值是一个递归的数据结构,可以使用Java的Map来实现。以下是一个示例代码,使用Map来表示一个无限套字典: ``` import java.util.HashMap; import java.util.Map; public class NestedDictionary { private Map<String, Object> dictionary = new HashMap<>(); public void setValue(String key, Object value) { String[] keys = key.split("\\."); Map<String, Object> currentDict = dictionary; for (int i = 0; i < keys.length - 1; i++) { String currentKey = keys[i]; if (!currentDict.containsKey(currentKey)) { currentDict.put(currentKey, new HashMap<String, Object>()); } currentDict = (Map<String, Object>) currentDict.get(currentKey); } currentDict.put(keys[keys.length - 1], value); } public Object getValue(String key) { String[] keys = key.split("\\."); Map<String, Object> currentDict = dictionary; for (int i = 0; i < keys.length - 1; i++) { String currentKey = keys[i]; if (!currentDict.containsKey(currentKey)) { return null; } currentDict = (Map<String, Object>) currentDict.get(currentKey); } return currentDict.get(keys[keys.length - 1]); } } ``` 这个示例代码的`NestedDictionary`类实现了一个无限套字典。`setValue`方法用于在字典设置一个键值对,`getValue`方法用于获取一个键对应的值。键可以是一个或多个用`.`分隔的字符串。 例如,可以使用以下代码来测试这个类: ``` NestedDictionary dict = new NestedDictionary(); dict.setValue("a.b.c", "value1"); dict.setValue("a.b.d", "value2"); dict.setValue("a.c.e.f", "value3"); System.out.println(dict.getValue("a.b.c")); // 输出"value1" System.out.println(dict.getValue("a.b.d")); // 输出"value2" System.out.println(dict.getValue("a.c.e.f")); // 输出"value3" System.out.println(dict.getValue("a.b")); // 输出null ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值