我正在实现一个ZipComparison
文件,它遍历目录树结构,并处理该目录树结构中MD5
的所有.zip
文件。
import java.io.*;
public class ZipComparison {
public class ZipFilenameFilter implements FilenameFilter {
public boolean accept(File dir, String name) {
if( name != null &&
( dir.isDirectory() || name.toLowerCase().endsWith(".zip"))) {
return true;
}
return false;
}
}
/**
* These two constant values are the root for the directory
*/
private static final String root_a = "D:/UDU/r/tc10.0.0.2012080100_A";
private static final String root_b = "D:/UDU/r/tc10.0.0.2012080100_B";
private ZipFilenameFilter filter;
public ZipComparison() {
this.filter = new ZipFilenameFilter();
}
public void matchMD5() {
try{
File root = new File( ZipComparison.root_a );
if( !root.exists() ){
System.out.println( "root doesn't exist" );
}
else if( !root.isDirectory() ) {
System.out.println( "root isn't a directory" );
}
else{
File[] files = new File( ZipComparison.root_a ).listFiles( this.filter );
if( files != null ){
showFiles( files );
}
else{
System.out.println( "List of files was null." );
System.exit( -1 );
}
}
}
catch(SecurityException ex){
ex.printStackTrace();
}
}
/**
* iterates over the directory tree structure.
* @param files
*/
public void showFiles( File[] files ){
for( File file : files ){
if( file.isDirectory() ) {
System.out.println( "Directory: " + file.getName() );
showFiles( file.listFiles( this.filter ) );
}
else {
System.out.println( "File: " + file.getName() );
}
}
}
/**
* @param args
*/
public static void main( String[] args ) {
// TODO Auto-generated method stub
ZipComparison zc = new ZipComparison();
zc.matchMD5();
System.exit( 0 );
}
}
当我在没有它的情况下执行程序时,ZipFilenameFilter filter
它工作得很好。但是,当我添加filter
到
File[] files = new File( ZipComparison.root_a ).listFiles( filter );
什么都没有打印出来。我错过了什么吗?