简体   繁体   English

从内部存储删除文件

[英]Deleting file from internal storage

如何使用Delphi for Android删除android内部存储中的文件或文件夹

You should use the TFile and TDirectory classes in the System.IOUtils unit. 您应该在System.IOUtils单元中使用TFileTDirectory类。

For example: 例如:

TDirectory.Delete(<YOUR DIR PATH>);

or 要么

TFile.Delete(<YOUR FILE PATH>);

Look in Embarcadero's documentation to get the right path of your files and folders on the various platforms: 查看Embarcadero的文档,以获取各种平台上文件和文件夹的正确路径:

Standard RTL Path Functions across the Supported Target Platforms 跨支持的目标平台的标准RTL路径功能

Referred from : 引自:

https://stackoverflow.com/a/27047502/5193608 https://stackoverflow.com/a/3554949/5193608 https://stackoverflow.com/a/27047502/5193608 https://stackoverflow.com/a/3554949/5193608

Main Part from both links: 来自两个链接的主要部分:

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. 删除文件的最直接方法是使打开的文件引用自身具有delete()。

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(): 如果文件保存在内部存储中,则还可以通过调用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(). 注意:当用户卸载您的应用程序时,Android系统将删除以下内容:您保存在内部存储中的所有文件使用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. 但是,您应该定期手动删除使用getCacheDir()创建的所有缓存文件,并定期删除不再需要的其他文件。

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

Directly you can do is : 您直接可以做的是:

File dir = getFilesDir();
File file = new File(dir, "my_filename");
boolean deleted = file.delete();

Hope,it helps! 希望能帮助到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM