Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8542505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:05:15+00:00 2026-06-11T12:05:15+00:00

I want to create and delete some files located in /data/data/providers/downloads/cache. So far, I

  • 0

I want to create and delete some files located in /data/data/providers/downloads/cache. So far, I can download target files and save in /data/data/providers/downloads/cache successfully, but when I trying to delete a file located in /data/data/providers/downloads/cache it fails in the end. My methods are as follows

File directory = new File("/data/data/providers/downloads/cache");
File[] files = directory.listFiles();

I want to list all files, so that I can find the target files need to be deleted.
I found that listFiles() method always return NULL, so my question is, can I use listFile() to the dir /data/data/providers/downloads/cache ?

Any ideals are welcomed.

BR
Alan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T12:05:16+00:00Added an answer on June 11, 2026 at 12:05 pm

    I use this method: when i want to delete all the files including the directory.

    static public boolean deleteDirectory(File path) {
        if( path.exists() ) {
            File[] files = path.listFiles();
            if (files == null) {
                return true;
            }
            for(int i = 0; i < files.length; i++) {
                if(files[i].isDirectory()) {
                    deleteDirectory(files[i]);
                }
                else {
                    files[i].delete();
                }
                Log.d("Deleting Files", files[i].getPath());
            }
        }
    
        return( path.delete() );
    }
    

    But android has it’s own clear cache method you can use, but it requires you to actually save stuff to the cache. The problem might be that you never add anything to it, and you only have permission to clear your own cache?

    How do I take advantage of Android's "Clear Cache" button Discusses the problem anyway 🙂

    Good luck

    EDIT:
    Also, are you sure your file path is correct? You can use

            Environment.getDownloadCacheDirectory()
    

    in order to find the root directory to the cache i think?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create some files in my component and then delete them. How
I want to create a JSF table like this . But instead delete button
i want create a custom json data from the mssql 2008 results so that
I want create an application with animate button? how can i do? after click
In my project I have to create some temp files in an USB device,
I want to create a small Ruby project with 10 ~ 20 classes/files. I
My task is to create an update installation pack wich delete some dlls and
As the title suggests, I need the ability to create, move, and delete files
I am working on application which will create some text files into the SD
When I create a Grails app, it comes with some default files in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.