作者:张昌昌
为了获取一个压缩包中的文件,而该压缩包里可能又含有压缩包 、文件夹、文件夹里又包含压缩包、文件等各种嵌套的情况,采用广度优先遍历和深度优先遍历的方法解决了此问题。
public static List getFilesOfZipAndRar(String zipPath) throws IOException
{
String destPath = zipPath.substring(0,zipPath.lastIndexOf(".")) + "/";
//先将该压缩文件解压
if(zipPath.contains(".zip"))
unZipFile(new File(zipPath),destPath);
if(zipPath.contains(".rar"))
unRarFile(new File(zipPath),destPath);
//进入解压目录,将该目录的所有zip都解压
recursiveCompressedFile(new File(destPath));
//得到该目录下的所有文件
Iterator iterator = Directory.walk(destPath).iterator();
List files = new ArrayList();
File file = null;
while(iterator.hasNext())
{
file = (File)iterator.next();
if(file.getName().contains(".rar"))
continue;