Copy Code code as follows:
Package com.famous.dark.util;
Import Java.io.File;
Import Java.io.FileFilter;
public class Myfilefilter implements FileFilter {
Public boolean accept (file file) {
String fileName = File.getname (). toLowerCase ();
if (Filename.endswith (". Jar") | | file.isdirectory ()) {
return true;
}
return false;
}
}
Copy Code code as follows:
Package com.famous.dark.util;
Import Java.io.File;
Import java.io.IOException;
Import Org.apache.commons.io.FileUtils;
Import Org.apache.commons.io.FilenameUtils;
/**
*
* @author Pat extracts the jar file from the file
*/
public class Jarcollectionutil {
Public String Collectionjar (File basefile, String targetfilepath) throws Exception {
File TargetDir = new file (Targetfilepath);
if (!targetdir.exists ()) {
Targetdir.mkdir ();
}
if (basefile.exists () && basefile.isdirectory ()) {
file[] files = basefile.listfiles (new Myfilefilter ());
for (File file:files) {
if (File.isdirectory ()) {
Collectionjar (file, Targetfilepath);
} else {
File TargetFile = new file (Targetfilepath + "\" + file.getname ());
Fileutils.copyfile (file, targetfile);
}
}
Return "Success";
} else {
Return "file path does not exist";
}
}
public static void Main (string[] args) throws Exception {
Jarcollectionutil collectionutil = new Jarcollectionutil ();
Collectionutil.collectionjar (New File ("f:\\jar\\lucene-4.3.1"), "F:\\jar\\lucene");
}
}