本文介绍了使用Java NIO将文件从一个目录移动到另一个目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用NIO库,但是当我尝试将文件从一个目录移动到另一个目录时,我会收到一个奇怪的错误。
I am using the NIO libraries but I am getting a strange error when I try to move files from one directory to another.
You have to construct the full destination path, file by file. If you want to copy /src/a.txt to /dest/2014/, the destination path needs to be /dest/2014/a.txt.
您可能想要这样做:
File srcFile = new File("/src/a.txt"); File destDir = new File("/dest/2014"); Path src = srcFile.toPath(); Path dest = new File(destDir, srcFile.getName()).toPath(); // "/dest/2014/a.txt"这篇关于使用Java NIO将文件从一个目录移动到另一个目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!