本文主要是介绍java读取zip文件,并将json中的反转义斜杆去除,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、pom文件
<!-- org.apache.commons/commons-text --><dependency><groupId>org.apache.commons</groupId><artifactId>commons-text</artifactId><version>1.8</version></dependency>
二、damo代码
package com.example.damo.testall.others;import org.apache.commons.text.StringEscapeUtils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;public class TestUnzip {public static void main(String[] args) {try {ZipFile zipFile = new ZipFile("D:\\testzip\\2020070717.zip");Enumeration<? extends ZipEntry> entries = zipFile.entries();while (entries.hasMoreElements()) {ZipEntry zipEntry = entries.nextElement();String name = zipEntry.getName();long size = zipEntry.getSize();if (size > 0) {BufferedReader bufferedReader =new BufferedReader(new InputStreamReader(zipFile.getInputStream(zipEntry)));String line;while ((line = bufferedReader.readLine()) != null) {// 去除反转义斜杠String jsonStr = StringEscapeUtils.unescapeEcmaScript(line);System.out.println(jsonStr.trim());}bufferedReader.close();}}zipFile.close();} catch (IOException e) {e.printStackTrace();}}
}
这篇关于java读取zip文件,并将json中的反转义斜杆去除的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!