[英]How to continue copying on error with copyDirectory from FileUtils (Apache Commons IO 2.4)
I am trying to copy files from one folder to another using the FileUtils method "static void copyDirectory(File srcDir, File destDir)" from apache commons io (2.4) with the following code: 我正在尝试使用以下代码使用来自apache commons io(2.4)的FileUtils方法“static void copyDirectory(File srcDir,File destDir)”将文件从一个文件夹复制到另一个文件夹:
String srcDir = "/sourceDirectory/examples/";
String destDir = "/tmp/examples/";
try{
FileUtils.copyDirectory(new File(srcDir), new File(destDir));
} catch (IOException e){
e.printStackTrace();
}
The file structure looks like the following: 文件结构如下所示:
examples/ (read access)
examples/.subdirectory (NO access)
examples/file1.txt (read access)
examples/file2.txt (read access)
examples/subdirectory2/file1.txt (read access)
examples/subdirectory2/file2.txt (NO access)
The problem is, that in srcDir there are a few files and one subdirectory I don't have access to. 问题是,在srcDir中有一些文件和一个我无权访问的子目录。 FileUtils.copyDirectory throws an "java.io.FileNotFoundException: .subdirectory (Permission denied)" and aborts. FileUtils.copyDirectory抛出“java.io.FileNotFoundException:.subdirectory(权限被拒绝)”并中止。
Is it possible to ignore those files I don't have permission to and just copy all the other files I can read? 是否可以忽略那些我没有权限的文件,只是复制我可以阅读的所有其他文件?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.