我正在尝试创建一个简单的java程序,它从zip文件中的文件中读取和提取内容.Zip文件包含3个文件(txt,pdf,docx).我需要阅读所有这些文件的内容,我正在使用Apache Tika.
有人可以帮我在这里实现功能.到目前为止我尝试过这个但没有成功
代码片段
public class SampleZipExtract {
public static void main(String[] args) {
List<String> tempString = new ArrayList<String>();
StringBuffer sbf = new StringBuffer();
File file = new File("C:\\Users\\xxx\\Desktop\\abc.zip");
InputStream input;
try {
input = new FileInputStream(file);
ZipInputStream zip = new ZipInputStream(input);
ZipEntry entry = zip.getNextEntry();
BodyContentHandler textHandler = new BodyContentHandler();
Metadata metadata = new Metadata();
Parser parser = new AutoDetectParser();
while (entry!= null){
if(entry.getName().endsWith(".txt") ||
entry.getName().endsWith(".pdf")||
entry.getName().endsWith(".docx")){
System.out.println("entry=" + entry.getName() + " " + entry.getSize());
parser.parse(input, textHandler, …Run Code Online (Sandbox Code Playgroud)