zoukankan      html  css  js  c++  java
  • 查询单个文件夹下的文件数以及删除

    查询文件夹下的文件数

    package example.file;
    
    import example.dao.FaceDao;
    
    import java.io.File;
    import java.io.IOException;
    
    public class RetrievalFlder {
        public static void main(String[] args) throws IOException {
    
            String path = "D:\tool\IDEA\workspace\ecloudtest\web\image";
            File file = new File(path);
            File[] list = file.listFiles();
    
            try {
                if (list.length>0) {
                    System.out.println("文件数:"+list.length);        
                }else{
                    System.out.println("该文件夹下没有文件");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
    
        }
    }

    删除指定文件

    package example.file;
    
    import java.io.File;
    
    public class DeleteFile {
        public static boolean deleteFile(String fileName) {
            // 文件路径
            File file = new File(fileName);
            // 如果文件路径所对应的文件存在,并且是一个文件,则直接删除
            if (file.exists() && file.isFile()) {
                if (file.delete()) {
                    System.out.println("删除文件" + fileName + "成功!");
                    return true;
                } else {
                    System.out.println("删除文件" + fileName + "失败!");
                    return false;
                }
            } else {
                System.out.println("删除文件失败:" + fileName + "不存在!");
                return false;
            }
        }
    }
  • 相关阅读:
    自动生成小学四则运算题目
    python自动生成小学四则运算题目
    大学排名
    中国大学排名
    pachong
    paiqiu
    文件管理
    软件工程课作业 2020-11-23
    时序图,E-R图,数据流程图
    考研信息查询系统需求规格说明书
  • 原文地址:https://www.cnblogs.com/vvxvv/p/14911251.html
Copyright © 2011-2022 走看看