How to get files in cache directory in android?

android, file

Solution

Change your code like this and try..

    File dir = new File(getCacheDir(), "test");
    if (dir.exists()) {
        for (File f : dir.listFiles()) {
            //perform here your operation
        }
    }

Problem

In my android app, I make files in a directory I get using this function (notice its putting in a subdirectory). ``` gsFile = new File(getCacheDir(), "test/aa.txt"); ``` But how do I iterate through the files in that directory now? I tried ``` File dir = new File(getCacheDir(), "test/aa.txt"); for (File f : dir.listFiles()) { } ``` but it crashed on File f

Original source