如何从SD卡中删除文件? [英] How to delete a file from SD card?

查看:33
本文介绍了如何从SD卡中删除文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建要作为电子邮件附件发送的文件.现在我想在发送电子邮件后删除图像.有没有办法删除文件?

I am creating a file to send as an attachment to an email. Now I want to delete the image after sending the email. Is there a way to delete the file?

我试过 myFile.delete(); 但它没有删除文件.

I have tried myFile.delete(); but it didn't delete the file.

我将此代码用于 Android,因此编程语言是 Java,使用通常的 Android 方式访问 SD 卡.当发送电子邮件后 Intent 返回到屏幕时,我正在删除 onActivityResult 方法中的文件.

I'm using this code for Android, so the programming language is Java using the usual Android ways to access the SD card. I am deleting the file in the onActivityResult method, when an Intent is returned to the screen after sending an email.

推荐答案

File file = new File(selectedFilePath);
boolean deleted = file.delete();

其中 selectedFilePath 是您要删除的文件的路径 - 例如:

where selectedFilePath is the path of the file you want to delete - for example:

/sdcard/YourCustomDirectory/ExampleFile.mp3

/sdcard/YourCustomDirectory/ExampleFile.mp3

这篇关于如何从SD卡中删除文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆