Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.File;

public class Main {
    public static int getNumOfFiles(String dirPath) {
        File dir = new File(dirPath);
        if (!dir.isDirectory()) {
            return 0;
        }

        File[] files = dir.listFiles();
        int numOfFiles = 0;
        for (File f : files) {
            if (f.isFile()) {
                numOfFiles++;
            }
        }

        return numOfFiles;
    }
}