我在 Android 上工作。我的要求是我有一个包含一些文件的目录,后来我将一些其他文件下载到另一个目录中,我的目的是将所有文件从最新目录复制到第一个目录中。在将文件从最新版本复制到第一个目录之前,我需要从第一个目录中删除所有文件。
最佳答案
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 数据库的有用文章。
关于android - 如何将我的文件从一个目录复制到另一个目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9600356/