将一个文件夹内的所有文件复制到别的文件夹
package ZiFuLiu;
import java.io.*;
public class CN { public static void main(String[] args) throws IOException{ //创建数据源File对象 File srcfile = new File("E:\\itheima"); //创建目的地File对象 File destfile = new File("D:\\"); //写方法实现文件夹的复制,参数是数据源对象和目的地对象 copyFoder(srcfile,destfile); } //复制文件的方法 private static void copyFoder(File srcfile, File destfile) throws IOException { //判断数据File是否是目录 if(srcfile.isDirectory()){ //在目的地下创建和数据源File名称一样的目录 String srcfilename = srcfile.getName(); File newFoder = new File(destfile, srcfilename);//D:\\itheima if(!newFoder.exists()){ newFoder.mkdir();//创建目录 } //获取数据源File下的所以文件或者File目录下的数组 File[] filearray = srcfile.listFiles();