java recursive file display

java recursive file display

Reads recursively all folders and subfolders

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;

import object.Java;
import utils.FileUtils;
public class RecursiveFileDisplay {

 static int folderCount = 0;
 static int fileCount = 0;
 static int noDetailsFound = 0;
 static Java response = new Java();

 public static void main(String[] args) throws IOException {
  // File currentDir = new File("."); // current directory
  String currentDir = "C:/Users/myworld/Desktop/java/";
  displayDirectoryContents(new File(currentDir));
  System.out.println("Total Folders : " + folderCount);
  System.out.println("Total Files :" + fileCount);
  System.out.println("NoDetailsFound :" + noDetailsFound);
  
        System.out.println(runningTime.totalTimeInMin());
 }

 public static void displayDirectoryContents(File dir) throws IOException {

  File[] files = dir.listFiles();

  for (File file : files) {
   if (file.isDirectory()) {
    System.out.println("directory:" + file.getName());
    folderCount = folderCount + 1;
    displayDirectoryContents(file);
   } else {
    System.out.println("     file:" + file.getName());
    fileCount = fileCount + 1;

    String javaClass = file.toPath().toString();
    String classWithPackage = javaClass.replaceAll("\\\\", ".").replaceFirst(".*Desktop.java.", "");
    String sb = new String(classWithPackage);
    String fullyQualifiedPackageName = null;
    response = new Java();
    response.setFilePath(file.toURI().toString());
    response.setSize(file.length() / 1024 + "KB");
    response.setFilename(file.getName());

    if (sb.substring(sb.length() - 5, sb.length()).toString().equals(".java") && true) {

     try {
      fullyQualifiedPackageName = sb.substring(0, sb.length() - 5).toString();
      response.setPackageName(fullyQualifiedPackageName.toString());
      
      ArrayList<String> fieldsList = listFields(Class.forName(fullyQualifiedPackageName));
      ArrayList<String> methodList = listMethods(Class.forName(fullyQualifiedPackageName));

      response.setFields(fieldsList.size());
      response.setMethods(methodList.size());
      response.setFieldsList(fieldsList);
      response.setMethodsList(methodList);
     } catch (Exception e) {
      System.out.println(e);
     } catch (ExceptionInInitializerError e) {
      System.out.println(e);
     }

    } else {
     noDetailsFound = noDetailsFound + 1;
     System.out.println("error file:" + fullyQualifiedPackageName);
     
    }

    FileUtils.writeFile("C:/Users/myworld/Desktop/meta.js", response.toString());
   }
  }

 }

 public static <T> ArrayList<String> listFields(Class<T> clazz) {
  ArrayList<String> feildList = new ArrayList<String>();
  Field[] allFields = clazz.getDeclaredFields();
  for (Field field : allFields) {
   feildList.add(field.getName().toString());
  }
  return feildList;

 }

 public static <T> ArrayList<String> listMethods(Class<T> clazz) {
  ArrayList<String> methodList = new ArrayList<String>();
  Method[] allMethods = clazz.getDeclaredMethods();
  for (Method method : allMethods) {
   methodList.add(method.getName().toString() + "()");
  }
  return methodList;
 }

}