我有一个文件夹,其中有一个 .dat 文件和一个 .zip 文件,我必须将 .zip 文件移动到另一个目录
我有两个文件夹,其中一个是
1) c:\source folder --> having two files abc.dat and other is abc.zip
2) c:\destination ---> in which zip shpould be get copied
请告知如何实现这一目标,我现在所做的事情是......
File directory = new File(sourceFolder);
File[] listFiles = (mcrpFilePath).listFiles();
for (File f : listFiles) {
if (f.isFile()) { // ?? here logic to pick up the zip file
//logic to move the zip file to other directory
}
}
最佳答案
Renames the file denoted by this abstract pathname.
Many aspects of the behavior of this method are inherently platform-dependent: The rename operation might not be able to move a file from one filesystem to another, it might not be atomic, and it might not succeed if a file with the destination abstract pathname already exists. The return value should always be checked to make sure that the rename operation was successful.
这里是Example
或者您可以使用Files#move (如果您使用的是 java 7)
Move or rename a file to a target file.
关于java - 将 zip 文件移动到其他目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18566655/