zoukankan      html  css  js  c++  java
  • 直接读取ZIP包数据 线上、线下方法

    public static void main(String[] args) {

           //

           String path = "C:\Users\hengy\Desktop\2019042414.zip";

           String dnFileUrl =

               "http://mbncontent.oss-ap-southeast-1.aliyuncs.com/TH/C792871848C74AC4/DN/2019042414.zip";

           ZipInputStream zipInputStream = null;

           BufferedReader br = null;

           try {

               // new

               URL url = new URL(dnFileUrl);

               //

               HttpURLConnection conn = (HttpURLConnection)url.openConnection();

               Charset utf8 = Charset.forName("UTF-8");

               int resultCode = conn.getResponseCode();

               if (HttpStatus.OK.value() == resultCode) {

                   zipInputStream = new ZipInputStream(conn.getInputStream(), utf8);

                   ZipEntry zipEntry;

                   while ((zipEntry = zipInputStream.getNextEntry()) != null) {

                       if (zipEntry.toString().endsWith("txt")) {

                           br = new BufferedReader(new InputStreamReader(zipInputStream));

                           String line;

                           while ((line = br.readLine()) != null) {

                               String[] infoArr = line.toString().split(",");

                               if (null != infoArr && infoArr.length > 1) {

                                   PayPigeonLeadsDnModel dnModel = new PayPigeonLeadsDnModel();

                                   dnModel.setTelco(infoArr[0]);

                                   dnModel.setShortcode(infoArr[1]);

                                   dnModel.setKeyword(infoArr[2]);

                                   dnModel.setMtid(infoArr[3]);

                                   dnModel.setMsisdn(infoArr[4]);

                                   dnModel.setStatus(infoArr[5]);

                                   if (infoArr.length >= 7) {

                                       dnModel.setStatusDetails(infoArr[6]);

                                   }

                                   //

                                   System.out.println(dnModel.toString());

                               }

                           }

                       }

                       System.out.println();

                   }

               }

           } catch (Exception e) {

               e.printStackTrace();

               LOGGER.error("Read zip file error. : {}", e.getMessage());

           } finally {

               try {

                   if (null != br) {

                       br.close();

                   }

                   if (null != zipInputStream) {

                       zipInputStream.close();

                   }

               } catch (IOException e) {

                   e.printStackTrace();

                   LOGGER.error("close zipInputStream error. : {}", e.getMessage());

               }

           }

           // //

           // ZipFile zipFile;

           // ZipInputStream zipInputStream = null;

           // try {

           // zipFile = new ZipFile(dnFileUrl);

           //

           // InputStream inputStream = new BufferedInputStream(new FileInputStream(dnFileUrl));

           // Charset utf8 = Charset.forName("UTF-8");

           // zipInputStream = new ZipInputStream(inputStream, utf8);

           // ZipEntry zipEntry;

           // while ((zipEntry = zipInputStream.getNextEntry()) != null) {

           // if (zipEntry.toString().endsWith("txt")) {

           // BufferedReader br =

           // new BufferedReader(new InputStreamReader(zipFile.getInputStream(zipEntry)));

           // String line;

           // while ((line = br.readLine()) != null) {

           // String[] infoArr = line.toString().split(",");

           // if (null != infoArr && infoArr.length > 1) {

           // PayPigeonLeadsDnModel dnModel = new PayPigeonLeadsDnModel();

           // dnModel.setTelco(infoArr[0]);

           // dnModel.setShortcode(infoArr[1]);

           // dnModel.setKeyword(infoArr[2]);

           // dnModel.setMtid(infoArr[3]);

           // dnModel.setMsisdn(infoArr[4]);

           // dnModel.setStatus(infoArr[5]);

           // if (infoArr.length >= 7) {

           // dnModel.setStatusDetails(infoArr[6]);

           // }

           // //

           // System.out.println(dnModel.toString());

           //

           // }

           // }

           // br.close();

           // }

           // System.out.println();

           // }

           // } catch (IOException e) {

           // e.printStackTrace();

           // LOGGER.error("Read zip file error. : {}", e.getMessage());

           // } finally {

           // try {

           // if (null != zipInputStream) {

           // zipInputStream.closeEntry();

           // }

           // } catch (IOException e) {

           // e.printStackTrace();

           // LOGGER.error("close zipInputStream error. : {}", e.getMessage());

           // }

           // }

       }

    欢迎一起来学习和指导,谢谢关注!
  • 相关阅读:
    python和web框架面试题目整理(2)
    Linux系统运维面试题目整理(1)
    python和web框架面试题目整理(1)
    2018-7-11 Django REST API小试牛刀
    2018-4-27 python实现systemd进程后台运行任务
    从git中删除.idea目录
    springboot中的banner素材
    IpUtils获取用户请求真实ip工具类
    导出sqlserver数据库设计语句
    nginx: [emerg] unknown directive "if(!-e" 错误解决
  • 原文地址:https://www.cnblogs.com/mask-xiexie/p/10880532.html
Copyright © 2011-2022 走看看