zoukankan      html  css  js  c++  java
  • java 读取Zip文件进行写入

    直接读取ZIp文件读取写入到别的文件中。

    package jp.co.misumi.mdm.batch;
    
    import java.io.BufferedReader;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.zip.GZIPInputStream;
    
    public class MainSample {
    
      public static void main(String[] args) {
        long start = System.currentTimeMillis();
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
          fis = new FileInputStream("D:/Misumi MDM/WorkSpace/mdmtsv/update_log_17631.tsv.gz");
          GZIPInputStream gzis = new GZIPInputStream(fis);
          InputStreamReader reader = new InputStreamReader(gzis);
          BufferedReader in = new BufferedReader(reader);
          
          fos = new FileOutputStream("D:/Misumi MDM/WorkSpace/mdmtsv/update_log_17631.tsv");
    
          String line = null;
          while ((line = in.readLine()) != null) {
            // System.out.println(readed);
            String[] datas = line.split("	", -1);
            if("m_product".equals(datas[2].toLowerCase())) {
              fos.write(line.getBytes());
              fos.write("
    ".getBytes());
            }
          }
          
          in.close();
        } catch (FileNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } finally {
          if (fis != null) {
            try {
              fis.close();
            } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
          }
          if (fos != null) {
            try {
              fos.close();
            } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
          }
          long end = System.currentTimeMillis();
          System.out.println("Total run Time is :" + (end - start) + "ms");
        }
      }
    
    }
  • 相关阅读:
    【墨天轮专访第四期】华为云GaussDB苏光牛:发挥生态优势,培养应用型DBA
    go语言中iota和左移<< 右移<<
    gin Http请求Body和Header的获取 request post form Query header
    C# 【::】符号用法
    HyperV 无法Ping通主机原因
    远程协助
    单独安装mysql客户端
    MySQL中间件之ProxySQL(3):初试读写分离
    ProxySQL:简介和安装(1)
    dbdeployer MySQL沙盒部署详解
  • 原文地址:https://www.cnblogs.com/sunxun/p/6700180.html
Copyright © 2011-2022 走看看