zoukankan      html  css  js  c++  java
  • JAVA获取文件夹下所有的文件

    package com.test;
    
    import org.junit.Test;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import java.io.File;
    
    /**
     *获取文件夹下所有的文件
     */
    public class FileTest {
        private static final Logger logger = LoggerFactory.getLogger(FileTest.class);
        @Test
        public void test(){
            getFileName("d://logs//");
        }
        private void getFileName(String filePath){
            if(null!=filePath&&"".equals(filePath)){
                File file = new File(filePath);
                //判断文件或目录是否存在
                if(!file.exists()){
                    logger.info("【"+filePath + " not exists】");
                }
                //获取该文件夹下所有的文件
                File[] fileArray= file.listFiles();
                File fileName = null;
                for(int i =0;i<fileArray.length;i++){
                    fileName = fileArray[i];
                    //判断此文件是否存在
                    if(fileName.isDirectory()){
                        logger.info("【目录:"+fileName.getName()+"】");
                    }else{
                        logger.info(fileName.getName());
                    }
                }
            }
        }
    }
  • 相关阅读:
    单表查询
    解读python中SocketServer源码
    C++实训(2.3)
    C++实训(2.2)
    C++实训(2.1)
    C++实训(1.3)
    C++实训(1.1)
    顺序表的实现,在vs2019上运行成功
    p243_5(3)
    自考新教材-p176_5(2)
  • 原文地址:https://www.cnblogs.com/qinxu/p/8192246.html
Copyright © 2011-2022 走看看