I'm trying to programmatically move files from the internal memory in Android to a existing directory in the SD card.
I tried two ways.
In the first one I used File.renameTo:
String destName = externalDirPath + File.separatorChar + destFileName;
File originFile = new File(cacheDirPath + File.separatorChar + originalfileName);
originFile.renameTo(new File(destName));
In the other I used Runtime.getRuntime():
Process p = Runtime.getRuntime().exec("/system/bin/sh -");
DataOutputStream os = new DataOutputStream(p.getOutputStream());
String command = "cp " + cacheDirPath + "/" + originalfileName+ " " + externalDirPath + "/" + destFileName+ "\n";
os.writeBytes(command);
With both of them it doesn't work..
Any suggestion?
Press “Source” and indicate the folder with the app's cache. It is located in Android/obb/the folder with the app's name. Press “Destination” to choose a folder on the SD card for the transfer. After every field is filled out, press the check mark in the top right corner and select the “pin” next to the Name field.
The cache directory is where files are stored during background uploads and after upload for quick access should you need to open the file from the network drive (Jungle Disk (Formerly Workgroup) and Desktop Edition users only).
Your Android phone's limited storage can fill up quickly. And one cause of this that's easy to overlook is the stored information that apps regularly create to run at their best. These temporary data files are known as a cache; a fair chunk of your Android phone's storage space might be filled up with cache files.
According to the Android API Reference of renameTo
,
Both paths be on the same mount point. On Android, applications are most likely to hit this restriction when attempting to copy between internal storage and an SD card.
You will probably have to read the File
into a byte[]
and then write it into a new File
.
This answer covers it.
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