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