I am downloading an Android application to the path: /mnt/sdcard/download/App.apk
using the DownloadManager
class. If the App.apk already exists, the download fails. How to replace the existing apk?
Asked
Active
Viewed 2,143 times
0

user1471575
- 731
- 2
- 15
- 23
1 Answers
3
DownloadManager
will not let you do this. You should delete or rename the existing file first.
File f = new File("/mnt/sdcard/download/App.apk");
if (f.exists()) {
f.delete();
// or
f.renameTo(...);
}

Graham Borland
- 60,055
- 21
- 138
- 179
-
How to check if the file already exists in order to delete it? – user1471575 Jun 22 '12 at 12:42