• java 直接读取zip文件和文件内容


    java 直接读取zip文件和文件内容 - 并发读取

    package com.lookcoder.utils;
    
    import java.io.*;
    import java.nio.charset.Charset;
    import java.nio.charset.StandardCharsets;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipFile;
    import java.util.zip.ZipInputStream;
    
    public class ReadFile implements Runnable {
        public static void main(String[] args) throws IOException {
            for (int i = 0; i < 500; i++) {
                new Thread(new ReadFile()).start();
            }
        }
    
        @Override
        public void run() {
            String path = "C:\Users\thunisoft\Desktop\plugman.zip";
            ZipInputStream zin = null;
            try {
                zin = new ZipInputStream(new FileInputStream(path), StandardCharsets.UTF_8);
                ZipFile zf = new ZipFile(path);
                ZipEntry ze;
                while ((ze = zin.getNextEntry()) != null) {
                    if (ze.toString().endsWith("/node_modules/define-property/package.json")) {
                        BufferedReader br = new BufferedReader(new InputStreamReader(zf.getInputStream(ze)));
                        String line;
                        StringBuilder sb = new StringBuilder();
                        while ((line = br.readLine()) != null) {
                            sb.append(line.toString().trim());
                        }
                        System.out.println(Thread.currentThread().getName() + " :: " + ze.getName() + " :: " + sb.toString());
                        br.close();
                        break;
                    }
                }
                System.out.println();
                System.out.println();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (zin != null) {
                    try {
                        zin.closeEntry();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
    

      

    Thread-123 :: plugman/node_modules/base/node_modules/define-property/package.json :: {"_from": "define-property@^1.0.0","_id": "define-property@1.0.0","_inBundle": false,
    Thread-214 :: plugman/node_modules/base/node_modules/define-property/package.json :: {"_from": "define-property@^1.0.0","_id": "define-property@1.0.0","_inBundle": false,
    Thread-109 :: plugman/node_modules/base/node_modules/define-property/package.json :: {"_from": "define-property@^1.0.0","_id": "define-property@1.0.0","_inBundle": false,

      

  • 相关阅读:
    dbcp 详细配置
    InetAddress
    Qrcode 二维码
    左值右值分析
    javaweb reponse 写出文件
    ehcache 在集群环境下 出现 Cause was not due to an IOException or NotBoundException
    lo4j 日志级别
    log4j xml配置
    cron 表达式
    RabbitMQ简介
  • 原文地址:https://www.cnblogs.com/hfultrastrong/p/12851176.html
Copyright © 2020-2023  润新知