import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
public class VideoCopier {
public static void main(String[] args) {
// 指定源文件夾路徑和目標文件夾路徑
String sourceFolderPath = "path/to/source/folder";
String destinationFolderPath = "path/to/destination/folder";
// 調(diào)用方法復(fù)制視頻文件
copyVideos(sourceFolderPath, destinationFolderPath);
}
private static void copyVideos(String sourceFolderPath, String destinationFolderPath) {
// 創(chuàng)建源文件夾對象
File sourceFolder = new File(sourceFolderPath);
// 獲取源文件夾下的所有文件和子文件夾
File[] files = sourceFolder.listFiles();
if (files != null) {
for (File file : files) {
if (file.isDirectory()) {
// 如果是子文件夾,則遞歸調(diào)用該方法處理子文件夾
copyVideos(file.getAbsolutePath(), destinationFolderPath);
} else {
// 如果是視頻文件,則復(fù)制到目標文件夾中
if (isVideoFile(file)) {
try {
Files.copy(file.toPath(), new File(destinationFolderPath, file.getName()).toPath(),
StandardCopyOption.REPLACE_EXISTING);
System.out.println("成功復(fù)制視頻:" + file.getName());
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
}
private static boolean isVideoFile(File file) {
// 判斷是否為視頻文件,這里簡單判斷后綴名為常見視頻格式即可,你可以根據(jù)實際需求進行修改
String fileName = file.getName();
String extension = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
return extension.equals("mp4") || extension.equals("avi") || extension.equals("mov");
}
}
實現(xiàn)效果:
文章來源:http://www.zghlxwxcb.cn/news/detail-646345.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-646345.html
到了這里,關(guān)于Java獲取指定文件夾下目錄下所有視頻并復(fù)制到另一個地方的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!