io流复制文件

xiaoxiao2025-07-18  7

JAVA 使用io流实现文件复制(空内容)

运用递归思想实现文件夹及子文件的复制

package com.neuedu.IO; import java.io.File; import java.io.IOException; public class FileCopy { public static void main(String[] args) { copy(new File("I:\\A"), new File("D:\\hh")); } public static void copy(File Old, File New) { File file = new File(New.getAbsoluteFile() + "/" + Old.getName()); file.mkdirs(); File[] files = Old.listFiles(); for (File file1 : files) { //判断是否还有子文件及文件夹 if (file1.isDirectory()) { copy(file1, file.getAbsoluteFile()); } else { File newFile = new File(file.getAbsoluteFile() + "/" + file1.getName()); try { newFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } } } }
转载请注明原文地址: https://www.6miu.com/read-5033304.html

最新回复(0)