- /**
- * 复制一个目录及其子目录的文件到另外一个目录
- */
- private void copyFolder(File src, File dest) throws IOException {
- if (src.isDirectory()) {
- if (!dest.exists()) {
- dest.mkdir();
- }
- String files[] = src.list();
- for (String file : files) {
- File srcFile = new File(src, file);
- File destFile = new File(dest, file);
- // 递归
- copyFolder(srcFile, destFile);
- }
- } else {
- InputStream in = new FileInputStream(src);
- OutputStream out = new FileOutputStream(dest);
- byte[] buffer = new byte[1024];
- int length;
- while ((length = in.read(buffer)) > 0) {
- out.write(buffer, 0, length);
- }
- in.close();
- out.close();
- }
- }
Java复制一个目录及其子目录的文件到另外一个目录
最新推荐文章于 2023-03-08 10:25:10 发布