Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: how to delete internal image file
    text
    copied!<p>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.</p> <p>I have successfully created and saved:</p> <pre><code>String imageName = System.currentTimeMillis() + ".jpeg"; FileOutputStream fos = openFileOutput(imageName, Context.MODE_PRIVATE); bitmap.compress(Bitmap.CompressFormat.JPEG, 35, fos); </code></pre> <p>an image that i receive through</p> <pre><code>bitmap = BitmapFactory.decodeStream(inputStream); </code></pre> <p>I am able to retrieve the image later for display:</p> <pre><code>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); </code></pre> <p>I now want to delete this file permanently. I have tried creating a new file and deleting it, but the file is not found:</p> <pre><code>File file = new File(imageName); file.delete(); </code></pre> <p>I have read on the android developer website that i must open private internal files using the <code>openFileInput(...)</code> method which returns an InputStream allowing me to read the contents, which i don't really care about - i just want to delete it.</p> <p>can anyone point me in the right direction for deleting a file which is stored in internal storage?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload