I was trying to get the List of packages from a java src folder by parsing it(using Files). Irrespective of the package structure (some may be com.example.abc, some may be com.example.xxyz.pqr, some may be com.application etc.) i want to get the list of packages in the src folder. Here is the function i've written. I'm getting very strange outputs. Please help me.
public static void displayIt(File node) {
    File[] subNode = node.listFiles();
    if (subNode.length == 1) {
        for (File file : subNode) {
            if (file.isDirectory()) {
                packageName = packageName + file.getName();
                displayIt(file);
            }
        }
    }
    else {
        subFolders = new ArrayList<String>();
        for (File file : subNode) {
            // parent.add(file.getName());
            subFolders.add(file.getName());
            if (file.isDirectory()) {
                File[] subDir = file.listFiles();
                for (File tempFile : subDir) {
                    if (tempFile.isDirectory()) {
                        // temp=file.getName()+"."+tempFile.getName();
                        packageList
                                .add(file.getName() + tempFile.getName());
                        displayIt(tempFile);
                    }
                }
            }
            displayIt(file);
        }
    }
}
 
     
    