Good day, there was a problem of the following nature. My application in the course of work creates one text file. When the user deletes the application from the phone, the file remains. Please tell me how to programmatically make so that this file was deleted too

    1 answer 1

    Write to the directory returned by the context.getFilesDir() call. In this case, you will not litter the device, and when you delete the application, all these files will be deleted automatically.

    A small example:

     File outputFile = new File(context.getFilesDir(), "filename"); 

    Or even easier:

     File outputFile = context.getFileStreamPath("filename"); 

    And then write to outputFile as usual.

    • but a small example is possible, otherwise it’s not immediately clear - Nikola Krivosheya
    • only swears at File outputFile = new File (Context.getFilesDir (), "filename"); the compiler (import did) writes: get the file from the type GetFilesDir () from the type Context be? - Nikola Krivosheya
    • The problem is that you have substituted the Context class itself instead of the context. And these methods are non-static , which the compiler reports to you. - falstaf