星涛:采用java递归复制文件夹
2024-10-09 19:31:56
package com.botao;
import java.io.*;
/**
* @author cbt28
*/
public class FileUtil {
public static String a="";
public static String b="";
public static void copyDir(File src, File target) throws IOException {
if (!target.exists()) {
target.mkdir();
}
File[] lf = src.listFiles();
for (File file : lf) {
if (file.isFile()) {
System.out.println(src + "\\" + file.getName() + "--->" + target + "\\" + file.getName());
boolean b = copyFile(new File(src + "\\" + file.getName()), new File(target + "\\" + file.getName()));
System.out.println(b);
} else {
copyDir(new File(src + "\\" + file.getName()), new File(target + "\\" + file.getName()));
}
}
}
public static boolean copyFile(File src, File target) throws IOException {
FileReader fr = new FileReader(src);
BufferedReader br = new BufferedReader(fr);
FileWriter fw = new FileWriter(target);
BufferedWriter bw = new BufferedWriter(fw);
String s = br.readLine();
while (s != null) {
bw.write(s);
bw.newLine();
s = br.readLine();
}
bw.close();
fw.close();
br.close();
fr.close();
return true;
}
}
最新文章
- checkbox选中状态不被改变
- java 22 - 6 多线程之线程调度和设置线程的优先级
- IO/ACM中来自浮点数的陷阱(收集向)
- 在ubuntu(linux)下安装vim,以及vim的常用命令
- How to Write Doc Comments for the Javadoc Tool
- C++:四种必须使用初始化列表情况
- Oracle的OracleBulkCopy不支持事务处理
- iscc2016 mobile1-TurtleShell.apk解题过程
- 背水一战 Windows 10 (38) - 控件(布局类): Panel, Canvas, RelativePanel, StackPanel, Grid
- linux下ClamAV使用
- 十一招让Ubuntu 16.04用起来更得心应手(转)
- arcgis api for js入门开发系列十六迁徙流动图
- Box布局
- 开发高性能JAVA应用程序基础(集合篇)
- [HAOI 2010]软件安装
- Pandas系列(九)-分组聚合详解
- Callable抛出异常与future.get
- 91. Reverse Linked List 反转链表
- 【Java】 剑指offer(39) 数组中出现次数超过一半的数字
- java:@SuppressWarnings注解
热门文章
- python - 平方根格式化 + 字符串分段组合
- oeasy教您玩转linux010109clear清屏
- Unity2018.4.7导出Xcode工程报错解决方案
- MySQL 增删查改 必知必会
- 安装cnpm设置npm淘宝镜像源
- 修改CentOS的yum源,改为阿里云的镜像
- idea报错cannot resolve symbol servlet
- agumaster 出现实际股票数据
- SpringMVC-结果跳转方式
- Python中的type(),isinstance,()dir(),的区别