I have Path Which is stored into one variable That is
String filepath="/mnt/sdcard/DCIM/Camera/1396854069062.jpg";
Now i want to rename only file that is 1396854069062.jpg I Reilly don't have any idea for how to do that.
File sdcard = Environment.getExternalStorageDirectory();
File from = new File(sdcard, filePath);
File to = new File(sdcard, "RChat_Rename.jpg";
from.renameTo(to);
Any help will b appreciated.
Thank You
File from = new File(directory, "currentFileName"); For safety, Use the File. renameTo() .
Open File Explorer by going to My Computer, or by pressing Windows Key + E on your keyboard. Find the file you want to rename, select it and select Rename on the ribbon (or press F2 on your keyboard). Type the new name you want the file to have and press Enter.
Locate the “My Files” folder on your Android device and tap to launch it. Inside the “My Files” folder, locate the file you’ll rename. Once you locate the file, long-press on it until it is selected. Tap the “More” button, which is shown as a kebab (3-vertical-dot icon) menu. On the menu that appears, select “Rename” by pressing it.
On the bottom, tap Browse . Tap a category or a storage device. You'll see files from that category in a list. Next to a file you want to rename, tap the Down arrow . If you don't see the Down arrow , tap List view .
Inside the “My Files” folder, locate the file you’ll rename. Once you locate the file, long-press on it until it is selected. Tap the “More” button, which is shown as a kebab (3-vertical-dot icon) menu. On the menu that appears, select “Rename” by pressing it. Encode the file’s new name on the space provided.
Launch the X-plore app and tap on Internal shared storage or select your memory card. Tap on the folder containing the files you want to organize. Select all the files you want to organize. Long-press on any of the selected files and tap Rename. A Batch rename menu should come up. Tap the edit icon on the row labeled Name.
Try this way,
File sdcard = Environment.getExternalStorageDirectory();
File from = new File(sdcard,"/1396854069062.jpg");
File to = new File(sdcard,"test.jpg");
from.renameTo(to);
Do not forget to add below permission in android manifest file
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Edit
String filepath= Environment.getExternalStorageDirectory() + "/DCIM/Camera/";
File from = new File(filepath,"1396854069062.jpg");
File to = new File(filepath,"test.jpg");
from.renameTo(to);
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