How to rename an existing file?
android, file, java
Solution
Try doing:
new File("loc/xyz1.mp3").renameTo(new File("loc/xyz.mp3"));
This should automatically overwrite the original file. This answer was taken from here: How to rename an existing file
Problem
I have 2 files , `File src = new File("loc/xyz.mp3")` and `File dst=new File("loc/xyz1.mp3")` Now , I want to rename `dst` to xyz.mp3 while delete `src` file. How can I accomplish this ? I was trying , ``` src.delete(); dst.renameTo(src); ``` I am running this in AsyncTask in background in my app , when I execute it first time , it works perfectly , however second time , it crashes. Please help how should I go about this.