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]);//再删除空文件夹
                    }
            }
     }

  • 相关阅读:
    QT调用其他UI并使用QLabel(text)
    QT调用单例模式脚本
    QT 调用另一个UI实现方式
    QT 键值
    (一) Mybatis 源码解析之源码概述
    设计模式之 模板模式开发
    十二、线程池
    (十一)并发容器ConcurrentHashMap
    mybatis plus 踩坑记 -- 自动填充
    C/C++ file
  • 原文地址:https://www.cnblogs.com/xiao-xu/p/3410696.html
Copyright © 2011-2022 走看看