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());

           // }

           // }

       }

    欢迎一起来学习和指导,谢谢关注!
  • 相关阅读:
    获取jsonPath的节点名称
    如何删除 macOS High Sierra 上的 swapfile
    Prototype fake it till make it.观后感
    intellij idea 初步环境熟悉
    一个比较综合的项目--》>图片缓存,下拉刷新等
    写的很好的博客->有关性能优化、图片缓存等
    layout优化之-》viewStub,requestFocus,merge,include
    有关ActionBar
    android:installLocation 解析
    Android开发效率—Eclipse快捷键
  • 原文地址:https://www.cnblogs.com/mask-xiexie/p/10880532.html
Copyright © 2011-2022 走看看