如何将文件从一个目录复制到另一目录? [英] How to copy my files from one directory to another directory?

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

问题描述

我正在使用Android。我的要求是我有一个包含一些文件的目录,后来我将一些其他文件下载到了另一个目录中,目的是将所有文件从最新目录复制到第一个目录中。在将文件从最新目录复制到第一个目录之前,我需要从第一个目录删除所有文件。

I am working on Android. 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.

推荐答案

    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();
       }
    }

我不记得在哪里找到了,但是这是我用来备份SQLite数据库的一篇有用的文章。

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天全站免登陆