public class IOTest { //拷贝文件,文件夹均可 public static void copyFile(String sourPath,String descPath){ File file = new File(sourPath); if (!file.exists()){ return; } String[] fileNames = file.list(); if (fileNames==null){ //拷贝文件 try { InputStream inputStream = new FileInputStream(sourPath); OutputStream outputStream = new FileOutputStream(descPath); byte[] bytes = new byte[100]; int i = -1; while ((i=inputStream.read(bytes))!=-1){ outputStream.write(bytes,0,i); } inputStream.close(); outputStream.close(); } catch (Exception e) { e.printStackTrace(); } } else { //确认是拷贝文件夹,创建目录 new File(descPath).mkdir(); for (String fileName:fileNames){ String sour = sourPath+"/"+fileName; String desc = descPath+"/"+fileName; copyFile(sour,desc); } } } }