package demo;import java.io.File;import java.io.IOException;import java.nio.file.Files;import java.nio.file.Paths;/*** @author yeqv* @program A2* @Classname A5* @Date /1/20 16:04* @Email w16638771062@*/public class A5 {//复制目录public static void main(String[] args) throws IOException {String a = "D:\\金山打字";String b = "D:\\银山打字";copy1(a, b);}public static void copy1(String a, String b) throws IOException {copy2(new File(a), new File(b));}public static void copy2(File file, File file1) throws IOException {if (!file1.exists()) {file1.mkdirs();}if (file.isDirectory()) {File[] files = file.listFiles();for (File file2 : files) {if (file2.isDirectory()) {copy2(file2, new File(file1.getPath(), file2.getName()));} else {Files.copy(file2.toPath(), Paths.get(file1.getPath() + "\\" + file2.getName()));}}}}}
300字范文,内容丰富有趣,生活中的好帮手!