Java - Copy file to another directory using FileUtils and copyFileToDirectory - doesn't work -?

我们两清 提交于 2019-12-03 12:47:36

Replicated your error and it only fails when the program does not have permission to write on destination folder. Even catching a throwable and printing stacktrace shows no info and the method is quite silent... if the folder does not exist, the method creates it so disregard that possible correction.

Check write permissions in destination folder

It is never a good idea to do swallow exceptions. Do an e.printstacktrace() in your exception handling mechanism for more information. Since you did not specify any other information, first thing that comes to mind is that if you are using Windows vista or later, usually it will ask you for administrator consent when placing items directly in your C:\ directory.

To see if this is the problem, I would recommend you test this out in other directories such as My Documents or else, disable the UAC.

Do

destDir.mkdirs();

or

FileUtils.forceMkdir(destDir);

to create the directory temp2 first.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!