Java統計文件數量


Java統計文件數量

package com.vfsd;

import java.io.File;
import java.io.IOException;

/*******************************************************************************************************
 * Copyright: vc1.0 2018. All rights reserved.                    <br>
 * The whole package including this class is licensed under        <br>
 *                                                                 <br>
 * @ClassName:                                        <br>
 * @Directory:                                        <br>
 * @author:           luozhubang                                    <br>
 * @version:         v1.0.0                                        <br>
 * @date:                                                <br>
 * @Description:                                                 <br>
 *       1、                                        <br>
 *       2、                                        <br>
 * @Others: 暫無說明                                                <br>
 * @Modification History:                                        <br>
 *       1、                                            <br>
 *       Date:                              <br>
 *       Author:                                        <br>
 *       Modification:                                     <br>
 *                                                                 <br>
 *       2、                                                        <br>
 *       Date:                                                  <br>
 *       Author:                                                   <br>
 *       Modification:                                          <br>
 *       
 * @Statement: If you are using the package or parts of it in any commercial way, a commercial license is required. <br>
 *   Visit <a href='http://www.bim-times.com'>http://www.bim-times.com</a> for more information.<br>
 * 
*********************************************************************************************************/
public class CountFileNum {
    private static int count1 = 0;
    public static void main(String[] args) throws IOException{
        String dir1="E:\\20190418_relationdata4\\";
        
        listFiles(dir1);
    }
    
    public static void listFiles(String filePath) throws IOException{
        File dirFile = new File(filePath);
        if(dirFile.isDirectory()) {
            File[] files1 = dirFile.listFiles();
            for(int i=0;i<files1.length;i++) {
                countNum(files1[i].getPath());
                System.out.println("count:"+count1+"     "+files1[i].getName());
                count1=0;
            }
        }
    }
    
    public static void countNum(String filePath) throws IOException{
        File dirFile = new File(filePath);
        if(dirFile.isDirectory()) {
            File[] files1 = dirFile.listFiles();
            for(int i=0;i<files1.length;i++) {
                if(files1[i].getName().endsWith("02.txt")) {
                    count1++;
                }
            }
            
        }
    }

}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM