java复制文件和java移动文件的示例分享
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;
}
}
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 将文件中的jar文件提取出来
*/
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 "文件路径不存在";
}
}
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");
}
}
上一篇: 解决idea导入ssm项目启动tomcat报错404的问题
下一篇: java读取文件字符集示例方法