Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get files in cache directory in android?

Tags:

file

android

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

like image 817
omega Avatar asked Nov 27 '13 07:11

omega


People also ask

How do I access cache files on Android?

At the top-right, tap on the three vertical dots to open the Chrome options menu. Tap History. Check “Cached images and files.”

Where are Android cache files stored?

Android cache files can be saved both on Android internal memory and external SD card. If you completely deleted the folder without doing backups, your data in Android internal memory or some of the external memory SD card will be removed.

How do I find app cache files?

On Android Studio you can use Device File Explorer to view /data/data/your_app_package/cache. Click View > Tool Windows > Device File Explorer or click the Device File Explorer button in the tool window bar to open the Device File Explorer.


1 Answers

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
        }
    }
like image 196
kalyan pvs Avatar answered Oct 01 '22 03:10

kalyan pvs