Android: Save two Bitmaps with same name in internal storage

送分小仙女□ 提交于 2019-12-12 02:03:40

问题


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


来源:https://stackoverflow.com/questions/23345048/android-save-two-bitmaps-with-same-name-in-internal-storage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!