moving files around on Froyo
in my application i create a temporary开发者_开发问答 file this way
File tmp = File.createTempFile("TEST_", null, getFilesDir());
this resolves in a file that toURI()zed corrisponds to something like
/data/data/it.lorenzoff.test/files/TEST_XXX.tmp
In certain circumstances, i'd like to move this file permanently on sdcard but this code
dest = new File("/sdcard/permanentFile");
tmp.renameTo(dest);
never works.
I'm already using these permissions
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
but renameTo continue returning false. What i'm doing wrong?
Thanks in advance
L.
The explanation can be found in documentation for File
:
Many failures are possible. Some of the more likely failures include:
- Write permission is required on the directories containing both the source and destination paths.
- Search permission is required for all parents of both paths.
- Both paths [must] 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.
In this case source and target file paths point to different mount points (these two mount points even have different file system). You only option is to manually copy the file to sdcard and then delete the file from internal storage.
精彩评论