I'm trying to delete a file by grabbing the Uri, which was created through something like this:
ImageEditPresenterImpl.imageArrayList.add(Uri.fromFile(file));
The file was created through this, where filesavename is the correct name:
public void SaveBytesToFile(byte[] bytes) {
FileOutputStream fos;
try {
fos = context.openFileOutput(filesavename, Context.MODE_PRIVATE);
fos.write(bytes);
fos.close();
} catch (FileNotFoundException e) {
Log.d("BitmapOperationsSave", "file not found");
e.printStackTrace();
} catch (IOException e) {
Log.d("BitmapOperationsSave", "io exception");
e.printStackTrace();
}
}
Then, I try to delete it by going:
Uri fileUri = ImageEditPresenterImpl.imageArrayList.get(0);
File file = new File(fileUri.getPath());
// Delete one file on cache
try {
FileUtils.forceDelete(file);
} catch (IOException e) {
e.printStackTrace();
}
The file exists (I'm checking file explorer on the device) but I get this exception:
04-09 18:27:04.948 31860-32346/coffeeteastudios.simplereno W/System.err: java.io.FileNotFoundException: File does not exist: /data/user/0/coffeeteastudios.simplereno/files/-KEgh_i63Lo1du0_0htm_-_-_0
04-09 18:27:04.949 31860-32346/coffeeteastudios.simplereno W/System.err: at org.apache.commons.io.FileUtils.forceDelete(FileUtils.java:1639)
04-09 18:27:04.949 31860-32346/coffeeteastudios.simplereno W/System.err: at coffeeteastudios.simplereno.Logic.Local.Conversion.BitmapOperations$DeleteFile.doInBackground(BitmapOperations.java:200)
04-09 18:27:04.949 31860-32346/coffeeteastudios.simplereno W/System.err: at coffeeteastudios.simplereno.Logic.Local.Conversion.BitmapOperations$DeleteFile.doInBackground(BitmapOperations.java:180)
04-09 18:27:04.949 31860-32346/coffeeteastudios.simplereno W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:295)
04-09 18:27:04.949 31860-32346/coffeeteastudios.simplereno W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
04-09 18:27:04.949 31860-32346/coffeeteastudios.simplereno W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
04-09 18:27:04.949 31860-32346/coffeeteastudios.simplereno W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
04-09 18:27:04.949 31860-32346/coffeeteastudios.simplereno W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
04-09 18:27:04.949 31860-32346/coffeeteastudios.simplereno W/System.err: at java.lang.Thread.run(Thread.java:818)
Does anyone know why?