删除文件与串SD卡机器人 [英] Delete File in SD Card android with string

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

问题描述

我有这样的字符串,

Cursor c = db.obtenerDatoEjercicio(selecID);
String stringFoto1 = c.getString(6).toString();

然后stringFoto1是等于文件:///mnt/sdcard/Pictures/neoadnEditGyM/GYM_2.2.jpg

then stringFoto1 is equals "file:///mnt/sdcard/Pictures/neoadnEditGyM/GYM_2.2.jpg"

该文件存在。

我要删除的SD该文件,我用下面的code:

I want to delete that file on the sd and I used the following code:

String stringFoto1 = "file:///mnt/sdcard/Pictures/neoadnEditGyM/GYM_2.2.jpg"
File archivo1 = new File(stringFoto1);
archivo1.delete();

但是,这并不正常工作,请帮助。

But this doesn't work, please help.

推荐答案

最后,我用另一种方法。

Finally, I used another method.

因为当我保存这张照片是用的完整路径。
我把只保留名称和环境。

Because when I saved the photo was with the full path. I put only keep the name and well accessed by "enviroment".

 String folderSD = Environment.getExternalStorageDirectory().toString()+"/Pictures/neoadnEditGyM/";

        Cursor c = db.obtenerDatoEjercicio(selecID);
        String stringFoto1 = c.getString(6).toString();
        String stringFoto2 = c.getString(7).toString();
        File foto1 = new File(folderSD+stringFoto1);
        if (foto1.exists()){
            foto1.delete(); 
            Toast.makeText(this, stringFoto1+" deleted.", Toast.LENGTH_LONG).show();
        }
        File foto2 = new File (folderSD+stringFoto2);
        if(foto2.exists()){
            foto2.delete();
            Toast.makeText(this, stringFoto2+" deleted.", Toast.LENGTH_LONG).show();
        }

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

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