将zip文件移动到其他目录 [英] moving the zip file to other directory

查看:334
本文介绍了将zip文件移动到其他目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件夹,其中有一个.dat文件,一个是.zip文件,我必须将.zip文件移动到另一个目录

I have a folder in which there is a .dat file and one is .zip file ,I have to move the .zip file to another directory

我有两个文件夹一个

1) c:\source folder --> having two files abc.dat and other is abc.zip
2) c:\destination  ---> in which zip shpould be get copied 

请告知如何实现这一点我现在所做的就是。 ..

please advise how to achiev this what I have done rite now is ...

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

            }
        }


推荐答案

使用 File.renameTo


重命名此抽象路径名表示的文件。

此方法行为的许多方面本质上都依赖于平台:重命名操作可能无法将文件从一个文件系统移动到另一个文件系统,它可能不是原子,如果具有目标抽象路径名的文件已存在,则可能不会成功。应始终检查返回值以确保重命名操作成功。

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.

这是示例

或者您可以使用文件#movement (如果你使用的是java 7)

Or you can use Files#move (if you are using java 7)


将文件移动或重命名为目标文件。

Move or rename a file to a target file.

这里是使用move()的示例

这篇关于将zip文件移动到其他目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆