This uses Commons IO, but itβs actually the easiest way to list all the directory names. It also has a more powerful set of filters that can be used for other purposes:
String[] dirNames = new File("/Users/jonathan").list(DirectoryFileFilter.INSTANCE); for (String dirName: dirNames) System.out.println("Directory Name: " + dirName);
source share