How to delete internal storage file in android?

后端 未结 8 2033
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-30 06:27

I have used the Android internal storage to save a file for my application (using openFileOutput) but I would like to delete that file, is it possible and how?<

相关标签:
8条回答
  • 2020-11-30 07:03

    You should always delete files that you no longer need. The most straightforward way to delete a file is to have the opened file reference call delete() on itself.

    myFile.delete();

    If the file is saved on internal storage, you can also ask the Context to locate and delete a file by calling deleteFile():

    myContext.deleteFile(fileName);

    Note: When the user uninstalls your app, the Android system deletes the following: All files you saved on internal storage All files you saved on external storage using getExternalFilesDir(). However, you should manually delete all cached files created with getCacheDir() on a regular basis and also regularly delete other files you no longer need.

    Source : http://developer.android.com/training/basics/data-storage/files.html

    0 讨论(0)
  • 2020-11-30 07:09
     void clearMyFiles() {
        File[] files = context.getFilesDir().listFiles();
        if(files != null)
            for(File file : files) {
               file.delete();
            }
     }
    
    0 讨论(0)
提交回复
热议问题