The fastest way to move a directory in Android?

What is the fastest way to move a directory in Android? In most cases, but not in all cases, the source and the recipient are in the same sdcard file system.

Current, my code goes through the entire directory structure and copies the contents of each file to a new file with the same name in a new location. Then it checks the file size matches, then deletes the original file.

For each file, the current current start (with additional exception handling):

    try{
      source = new FileInputStream(fileFrom).getChannel();
      destination = new FileOutputStream(fileTo).getChannel();
      destination.transferFrom(source, 0, source.size());
    } finally {
      source.close();
      destination.close();
    }

This seems to be slow, as well as a lot of computational work for what I expect, maybe this is a simple instant modification of the node at the source file system level.

+3
source share
1 answer

, File # renameTo (File).

if (!fileFrom.renameTo(fileTo)) {
    copy(fileFrom, fileTo);
    // delete(fileFrom);
}
+4

All Articles