What is the fastest way to move a directory in Android? In most, but not all cases, the source and destination are located on the same sdcard file system.
Current, my code goes through the entire directory structure, and copy the content of each file into a new file with the same name in the new location. It then verifies the file size matches, then deletes the source file.
For each file, I current run (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 way to much computational work for what I expect could maybe be a simple instant "node modification" at the raw file system level.
As long as Files are on the same filesystem you can actually move them File#renameTo(File).
if (!fileFrom.renameTo(fileTo)) {
copy(fileFrom, fileTo);
// delete(fileFrom);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With