集册 Java实例教程 在Zip文件中查找文件

在Zip文件中查找文件

欢马劈雪     最近更新时间:2020-01-02 10:19:05

803
在Zip文件中查找文件

 

import java.io.IOException;

import java.util.Enumeration;

import java.util.zip.ZipEntry;// from nowjava.com - 时代Java

import java.util.zip.ZipFile;

 

public class Main {

       

        public static void main(String args[])

        {

                 try

                 {

                        ZipFile sourceZipFile = new ZipFile("c:/Demo.zip");

                        String searchFileName = "readme.txt";

                        Enumeration e = sourceZipFile.entries();

                        boolean found = false;

                       

                        System.out.println("Trying to search " + searchFileName + " in " + sourceZipFile.getName());

                       

                        while(e.hasMoreElements())/** 来 自 nowjava - 时代Java**/

                        {

                                ZipEntry entry = (ZipEntry)e.nextElement();

                               

                                if(entry.getName().toLowerCase().indexOf(searchFileName) != -1)

                                {

                                        found = true;

                                        System.out.println("Found " + entry.getName());

                                }

                        }

                       

                        if(found == false)

                        {

                                System.out.println("File :" + searchFileName + 
展开阅读全文