//复制文件方法 public static void copy(File startFile,File endFile) throws IOException { BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(startFile)); BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(endFile)); byte[] bys = new byte[1024]; int len; while ((len = bufferedInputStream.read(bys)) != -1) { bufferedOutputStream.write(bys,0,len); } bufferedOutputStream.close(); bufferedInputStream.close(); } public static void main(String[] args) throws IOException { File file = new File("E:\\File"); File file1; File file2; //复制一级文件 File[] files = file.listFiles(); for (File _file : files) { file1 = new File(file,_file.getName()); file2 = new File("E:\\Case",_file.getName()); if (_file.isDirectory()) { file2.mkdir(); //复制二级文件 File[] _file1 = _file.listFiles(); for (File __file:_file1) { File file11 = new File(file1,__file.getName()); File file21 = new File(file2,__file.getName()); if (__file.isDirectory()) { file21.mkdir(); }else { copy(file11,file21); } } }else { copy(file1,file2); } } }
复制多级文件代码怎么用递归实现,我不太会
最新推荐文章于 2024-11-03 11:01:20 发布