SIMPLE JAVA PROGRAM TO KNOW NUMBER OF FILES IN DIRECTORY
CODE :
import java.io.*;
public class CountFilesInDirectory {
public static void main(String[] args) {
File f = new File("D:/SONGS");
int count = 0;
for (File file : f.listFiles()) {
if (file.isFile()) {
count++;
}
}
System.out.println("Number of files: " + count);
// Also do it with bellow one line code...
System.out.println(new File("D:/SONGS").listFiles().length);
}
}
No comments:
Post a Comment