直接读取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());
// }
// }
}
欢迎一起来学习和指导,谢谢关注!
本文来自博客园,作者:xiexie0812,转载请注明原文链接:https://www.cnblogs.com/mask-xiexie/p/10880532.html
分类:
java
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了