0

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?

lawonga
  • 832
  • 10
  • 20
  • the error says the file doesnt exist. are you sure it is there? – Shmuel Apr 10 '16 at 01:40
  • Maybe this help: http://stackoverflow.com/questions/3401579/get-filename-and-path-from-uri-from-mediastore?answertab=active#tab-top – Farshad Apr 10 '16 at 02:10
  • @shmuel yeah i'm sure :( but doing: context.getFileStreamPath(fileprefix + "_-_-_" + position) does work though! – lawonga Apr 10 '16 at 02:13

0 Answers0