如何把文件从一个目录复制到另一个目录 [英] How to Copy my files from one Directory to another Directory

查看:151
本文介绍了如何把文件从一个目录复制到另一个目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的机器人。
我的要求是,我有一些文件,一个目录,后来我下载了一些其它文件到另一个目录和我的意图是将所有的文件从最新的目录复制到第一directory.And从最新我需要的文件复制到一个目录之前以从第一目录中删除所有文件。
任何人可以帮助我。
先谢谢了。


解决方案

 无效copyFile(SRC文件,文件DST)抛出IOException
       FileChannel随路=新的FileInputStream(SRC).getChannel();
       FileChannel outChannel =新的FileOutputStream(DST).getChannel();
       尝试{
          inChannel.transferTo(0,inChannel.size(),outChannel);
       } {最后
          如果(随路!= NULL)
             inChannel.close();
          如果(outChannel!= NULL)
             outChannel.close();
       }
    }

我不记得在那里我发现这一点,但它是从我用来备份有用的文章SQLite数据库。

I am working on Android. And my requirement is that I have one directory with some files, later I downloaded some other files into another Directory and my intention is to copy all the files from latest directory into first directory.And before copying the files into first directory from latest I need to remove all files from the first directory. can anybody help me out . Thanks in advance.

解决方案

    void copyFile(File src, File dst) throws IOException {
       FileChannel inChannel = new FileInputStream(src).getChannel();
       FileChannel outChannel = new FileOutputStream(dst).getChannel();
       try {
          inChannel.transferTo(0, inChannel.size(), outChannel);
       } finally {
          if (inChannel != null)
             inChannel.close();
          if (outChannel != null)
             outChannel.close();
       }
    }

I can't remember where I found this, but it was from a useful article I used to backup a SQLite database.

这篇关于如何把文件从一个目录复制到另一个目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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