java复制文件和java移动文件的示例分享
时间:2023-09-17 08:18:06
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");
}
}
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java通过Fork/Join优化并行计算
Android利用Flutter实现立体旋转效果
![](https://img.aspxhome.com/file/2023/9/96759_0s.png)
C# Winform实现自定义漂亮的通知效果
Java字符串split使用方法代码实例
![](https://img.aspxhome.com/file/2023/2/68002_0s.png)
详解Android中Notification通知提醒
![](https://img.aspxhome.com/file/2023/0/120080_0s.png)
Java运行时数据区概述详解
![](https://img.aspxhome.com/file/2023/0/69130_0s.png)
springboot+springmvc实现登录拦截
java 获取当前路径下的所有xml文档的方法
C#判断系统是32位还是64位的方法
![](https://img.aspxhome.com/file/2023/9/108799_0s.png)
C#实现目录跳转(TreeView和SplitContainer)的示例代码
![](https://img.aspxhome.com/file/2023/4/92964_0s.jpg)
三步轻松搭建springMVC框架
![](https://img.aspxhome.com/file/2023/6/64036_0s.jpg)
Mybatis-plus自定义SQL注入器查询@TableLogic逻辑删除后的数据详解
android实现在横竖屏切换时页面信息不被重置的示例分享
Android精灵动画用法实例
在类库或winform项目中打开另一个winform项目窗体的方法
利用C#实现分割GIF图片
![](https://img.aspxhome.com/file/2023/7/113807_0s.png)
Java 实战图书管理系统的实现流程
![](https://img.aspxhome.com/file/2023/1/64541_0s.png)
System.getProperty(user.dir)定位问题解析
![](https://img.aspxhome.com/file/2023/8/79198_0s.png)
关于WPF异步MVVM等待窗体的介绍
![](https://img.aspxhome.com/file/2023/0/98190_0s.png)