Android的:如何删除内部图像文件 [英] Android: how to delete internal image file
问题描述
我想要做的:删除我的应用程序从专用内部存储的图像文件。我保存在内部存储的图像,使它们的应用程序卸载删除。
What i want to do: delete an image file from the private internal storage in my app. I save images in internal storage so they are deleted on app uninstall.
我已经成功地创建并保存:
I have successfully created and saved:
String imageName = System.currentTimeMillis() + ".jpeg";
FileOutputStream fos = openFileOutput(imageName, Context.MODE_PRIVATE);
bitmap.compress(Bitmap.CompressFormat.JPEG, 35, fos);
这是我收到过
bitmap = BitmapFactory.decodeStream(inputStream);
我能够再次找到该图像显示:
I am able to retrieve the image later for display:
FileInputStream fis = openFileInput(imageName);
ByteArrayOutputStream bufStream = new ByteArrayOutputStream();
DataOutputStream outWriter = new DataOutputStream(bufStream);
int ch;
while((ch = fis.read()) != -1)
outWriter.write(ch);
outWriter.close();
byte[] data = bufStream.toByteArray();
bufStream.close();
fis.close();
imageBitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
我现在想永久删除此文件。我曾尝试创建一个新的文件,并删除它,但找不到该文件:
I now want to delete this file permanently. I have tried creating a new file and deleting it, but the file is not found:
File file = new File(imageName);
file.delete();
我已经阅读了Android开发者网站,我必须使用 openFileInput(...)
方法,该方法返回一个InputStream让我阅读的内容,打开专用的内部文件,我真的不关心 - 我只是想删除
I have read on the android developer website that i must open private internal files using the openFileInput(...)
method which returns an InputStream allowing me to read the contents, which i don't really care about - i just want to delete it.
任何人都可以点我在正确的方向删除存储在内部存储的文件?
can anyone point me in the right direction for deleting a file which is stored in internal storage?
推荐答案
(ERG),我发现自己的答案。答案很简单太:(
Erg, I found the answer myself. Simple answer too :(
所有你需要做的就是调用 DELETEFILE(imageName)
方法。
All you have to do is call the deleteFile(imageName)
method.
if(activity.deleteFile(imageName))
Log.i(TAG, "Image deleted.");
完成!
这篇关于Android的:如何删除内部图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!