public static void main(String[] args) throws IOException {
// 指定要查找的文件名
String name = ".CR3"
// // 指定要查找的路径
String path = "G:\4K\img"
String path1 = "G:\4K\img-cr3"
copyDir(path,path1)
}
public static void copyDir(String srcPath, String destPath) throws IOException {
File srcFile = new File(srcPath)
File[] files = srcFile.listFiles()
if (files == null) {
return
}
File destFile = new File(destPath)
if (!destFile.exists()) {
destFile.mkdirs()
}
for (File file : files) {
if (file.isFile()) {
if (file.getName().endsWith(".CR3")) {
FileInputStream fis = new FileInputStream(file)
FileOutputStream fos = new FileOutputStream(new File(destPath + File.separator + file.getName()))
byte[] buffer = new byte[1024]
while (fis.read(buffer) != -1) {
fos.write(buffer)
}
fos.flush()
fos.close()
fis.close()
}
} else if (file.isDirectory()) {
copyDir(file.getPath(), destPath + File.separator + file.getName())
}
}
}
}