zoukankan      html  css  js  c++  java
  • Android 删除SD卡中的文件和文件夹

    //folderPath为文件路径

    public void delFolder(String folderPath) {

            try {

                    delAllFile(folderPath); //删除完里面所有内容

                    String filePath = folderPath;

                    filePath = filePath.toString();

                    java.io.File myFilePath = new java.io.File(filePath);

                    myFilePath.delete(); //删除空文件夹

            }

            catch (Exception e) {

                    System.out.println("删除文件夹操作出错");

                    e.printStackTrace();

            }  

    }

    public void delAllFile(String path) {
            File file = new File(path);
            if (!file.exists()) {
                    return;
            }
            if (!file.isDirectory()) {
             return;
            }
            String[] tempList = file.list();
            File temp = null;
            for (int i = 0; i < tempList.length; i++) {
                    if (path.endsWith(File.separator)) {
                            temp = new File(path + tempList[i]);
                    }
                    else {
                            temp = new File(path + File.separator + tempList[i]);
                    }
                    if (temp.isFile()) {
                            temp.delete();
                    }
                    if (temp.isDirectory()) {
                            delAllFile(path+"/"+ tempList[i]);//先删除文件夹里面的文件
                            delFolder(path+"/"+ tempList[i]);//再删除空文件夹
                    }
            }
     }

  • 相关阅读:
    Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could
    Spring Boot @Validation @Valid
    Spring Boot高版本配置数据库连接驱动问题
    Spring Boot应用建议及脚手架工程
    Motan RPC
    JSON Web Tokens介绍
    SpringBoot脚手架工程集成jwt
    JWT与Zuul
    基于Spring oauth2.0统一认证登录,返回自定义用户信息
    @JsonIgnore失效
  • 原文地址:https://www.cnblogs.com/xiao-xu/p/3410696.html
Copyright © 2011-2022 走看看