如何删除从SD卡中的所有文件中的android? [英] How to delete all the files from sd card in android?

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

问题描述

  

可能重复:
  <一href="http://stackoverflow.com/questions/6006811/how-to-delete-entire-contents-of-sdcard-programmatically-in-android-2-2">How删除编程方式在Android的SD卡的全部内容2.2

我想清除所有的Andr​​oid设备编程

文件

任何人都可以给我建议的方式或code,因此,我可以执行此操作,请...

在此先感谢。

解决方案

 公共静态布尔deleteDirectory(文件路径){
        // TODO自动生成方法存根
        如果(path.exists()){
            文件[]文件= path.listFiles();
            的for(int i = 0; I&LT; files.length;我++){
                如果(文件[I] .isDirectory()){
                    deleteDirectory(文件[I]);
                }
                其他 {
                    文件[I] .delete();
                }
            }
        }
        返程(path.delete());
    }
 

添加code就叫它曾经当需要使用目录的路径删除或要删除的文件

Possible Duplicate:
How to delete entire contents of sdcard programmatically in Android 2.2

I want to clear all the files from android device programmatically.

Can anyone suggest me the way or code, Hence I can perform this operation please...

Thanks in advance.

解决方案

public static boolean deleteDirectory(File path) {
        // TODO Auto-generated method stub
        if( path.exists() ) {
            File[] files = path.listFiles();
            for(int i=0; i<files.length; i++) {
                if(files[i].isDirectory()) {
                    deleteDirectory(files[i]);
                }
                else {
                    files[i].delete();
                }
            }
        }
        return(path.delete());
    }

add the code just call it when ever you require using the path of the directory to delete or the file to delete

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

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