删除文件与串SD卡机器人机器人、文件、SD

2023-09-06 10:05:31 作者:呜咽少女

我有这样的字符串,

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();
        }