private static File getChooserInitialDirectory(File referenceFile) {
        // Search for an existing directory
        while (referenceFile != null){
            if(Files.isDirectory(referenceFile.toPath())) {
                return referenceFile;
            }
            referenceFile = referenceFile.getParentFile();
        }

        // No parent file could be found or referenceFile
        // Default to returning a path to the first drive available
        return FileSystems.getDefault().getRootDirectories().iterator().next().toFile();
    }
Resolve a file to a valid base browsing directory
@param referenceFile The base directory or a child file that should be used as a browsing base path
@return A valid directory's File object
src/main/java/com/kodedu/service/impl/DirectoryServiceImpl.java