If I save a Bitmap called "picture.jpg" in internal storage and some steps later I save another Bitmap called "picture.jpg" too, what happens then? Does the second Bitmap overwrite the first or are there two Bitmaps with the same name then?
Asked
Active
Viewed 1,838 times
1
-
You **can't have** two files with the same name and same extension. If the file is open, you'll get an error, else it's overwritten by the new one. – Phantômaxx Apr 28 '14 at 15:28
-
So the second Bitmap will overwrite the first? That would be good. – L3n95 Apr 28 '14 at 15:55
-
If the first is **not already open** in some context. Or you'll get an error (which you can intercept and manage). – Phantômaxx Apr 28 '14 at 15:57
-
try this https://stackoverflow.com/a/63118912/4685284 – Shahbaz Hashmi Jul 27 '20 at 15:53
1 Answers
3
It will show you an error, I suggest you could use a dynamic file name or delete it before saving, in the case of dynamic, you could use something like this:
static int fCount = 0;
File file = new File(Environment.getExternalStorageDirectory()
+ File.separator + "/test" + String.valueOf(fCount++) +".jpg" );
Or
File file = new File(getExternalCacheDir(), "test.jpg" ); if (file.exists()) { boolean deleted = file.delete(); }

user3471194
- 62
- 1
- 3