Android: Save two Bitmaps with same name in intern

2019-08-24 02:39发布

问题:

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?

回答1:

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(); }