Sample sharing for Java copy files and Java moving files _java

Source: Internet
Author: User

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");
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.