简体   繁体   English

如何使用apache commons io复制空目录?

[英]How to copy empty directories with apache commons io?

I want to copy a directory tree with empty (but necessary!) directories with apache commons io 2.1 . 我想使用apache commons io 2.1复制具有空(但必要!)目录的目录树。 But it doesn't copy empty directories! 但是它不会复制空目录!

My code looks like this: 我的代码如下所示:

FileUtils.copyDirectory(new File(sourceDir), new File(targetDir));

Can I tell FileUtils to copy empty directories too? 我可以告诉FileUtils复制空目录吗? Or is it a bug in "commons io"? 还是“ commons io”中的错误?

I just tested this myself using apache commons 2.1 (using the code line below) and for me it does copy empty directories too. 我只是使用apache commons 2.1(使用下面的代码行)自己进行了测试,对我来说它复制了空目录。

FileUtils.copyDirectory(new File("/home/aioobe/tmp/new_test"),
                        new File("/home/aioobe/tmp/new_test_2"));

with this structure 具有这种结构

/home/aioobe/tmp/new_test
  hello.txt
  emptyDir/

Both hello.txt and emptyDir showed up in new_test_2 as well. hello.txtemptyDir都出现在new_test_2中。

Perhaps an SSCCE would be useful. SSCCE可能会有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM