package com.example.ss_0203_array.test.test_0826; import java.io.*; public class test2 { public static void main(String[] args) throws IOException { File src = new File("F:\\阿里云盘下载\\B站黑马java基础\\day10_字符串\\代码\\mystring"); File dist = new File("F:\\阿里云盘下载\\B站黑马java基础\\day10_字符串\\代码\\myVV"); copydir(src,dist); } private static void copydir(File src, File dist) throws IOException { dist.mkdir(); File[] files = src.listFiles(); for (File file : files) { if (file.isFile()){ FileInputStream fis = new FileInputStream(file); FileOutputStream fos = new FileOutputStream(new File(dist,file.getName())); byte[] bys = new byte[1024]; int len; while ((len = fis.read(bys)) != -1){ fos.write(bys,0,len); } fos.close(); fis.close(); }else{ copydir(file,new File(dist,file.getName())); } } } }
标签:src,dist,file,java,练习,复制,File,new From: https://www.cnblogs.com/pangchunlei/p/17658526.html