Reputation: 404
I have been trying to rename the file from external storage (Sdcard) using below code.But not rename the file, boolean return the false value.This code working fine for internal storage (Phone memory)
File f1= new File(sdcard_current_path);
File f2= new File(sdcard_rename_path);
boolean isSuccess=f1.renameTo(f2);
Upvotes: 1
Views: 2485
Reputation: 1919
To use function renameTo() your source and destination should be on same mount point see android doc https://developer.android.com/reference/java/io/File#renameTo(java.io.File)
Hope it will help you to resolve the issue.
Upvotes: 0
Reputation: 150
Make sure is directory present in storage. you can use the following code
File f1= new File(sdcard_current_path, filename);
File f2= new File(sdcard_rename_path, newfilname);
boolean isSuccess=f1.renameTo(f2);
Upvotes: 1
Reputation: 1420
First add this line to AndroidManifest.xml
:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Then use your code.
Upvotes: 0