This is my code for counting all the files in my comp, the code has not stopped running and there are over 2000000 files, is this normal, or is the code in an infinite loop. THanks for all the help :)
import java.io.*;
import java.util.*;
//got the framework from this link: stackoverflow.com/questions/3154488
public class RFF {
public static void main(String [] args) {
File[] files = new File("/Users").listFiles();
showFiles(files);
System.out.println(size);
}
static File file1 = new File ("/Users/varun/Desktop/a.pdf");
static double size = file1.length();
static int i = 0;
public static void showFiles(File[] files) {
try {
for (File file: files) {
if (file.isDirectory()) {
if (file.isFile() == true)
i++;
else
i = i;
if (file.length() > size)
size = file.length();
System.out.println("FileCount: " + i + ">>> FileSize: " +file.length() + " >>> FileName: " + file.getName() );
showFiles(file.listFiles()); // Calls same method again.
} else {
i++;
if (file.length() > size)
size = file.length();
System.out.println("FileCount: " + i + ">>> FileSize: " + file.length() + " >>> FileName: " + file.getName() );
}
}
} catch (NullPointerException e) {
System.out.println ("Exception thrown :" + e);
}
}
}