import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class DeepCopy { public static void main(String[] args){ deepCopy("F:/Software/所有字体", "F:/Software/All_Font"); } // 将folder_source所有文件(不包括文件夹)全部拷贝到dest_folder, private static void deepCopy(String folder_source, String dest_folder){ File file1 = new File(folder_source); if (file1.isFile()){ copy(file1.getAbsolutePath(), dest_folder+"/"+file1.getName()); }else if (file1.isDirectory()){ File[] files2 = file1.listFiles(); for (int i = 0; i < files2.length; i++){ deepCopy(files2[i].getAbsolutePath(), dest_folder); } } } public static boolean copy(String fileFrom, String fileTo) { try { InputStream in = new FileInputStream(fileFrom); OutputStream out = new FileOutputStream(fileTo); byte[] bt = new byte[1024]; int count; while ((count = in.read(bt)) > 0) { out.write(bt, 0, count); } in.close(); out.close(); System.out.println("Copy Finished!"); return true; } catch (IOException ex) { ex.printStackTrace(); return false; } } }
时间: 2024-12-22 11:04:23