title: Java - Read files in a directory to a HashMap - recursive
body: <p>Here below am trying to read fileNames from a nested folder structure into a hashmap,<br>
  Structure is like  </p>
  
  <pre><code>Main Folder  
        -&gt; EN (SubFolder1)  
               -&gt; File1
               -&gt; File2
        -&gt; FR (SubFolder2)  
               -&gt; File3
               -&gt; File4
        -&gt; GE (SubFolder3)  
               -&gt; File5
               -&gt; File6 
  </code></pre>
  
  <p>HashMap contains "Sub FolderName" as Key &amp; "FileNames"(ArrayList) as value.  </p>
  
  <p>I'm trying to make a recursive call &amp; save things into HashMap, but missing something in that, things are not being saved into HashMap.  </p>
  
  <pre><code>public static HashMap&lt;String,ArrayList&lt;String&gt;&gt; listFilesForFolder(File folder)
          throws IOException {
      HashMap&lt;String, ArrayList&lt;String&gt;&gt; dirFiles = new HashMap&lt;String, ArrayList&lt;String&gt;&gt;();
      if(folder.isDirectory()) {
          ArrayList&lt;String&gt; fileNames = new ArrayList&lt;String&gt;();
          for (final File fileEntry : folder.listFiles()) {
              if (fileEntry.isDirectory()) {
                  listFilesForFolder(fileEntry);
                  dirFiles.put(folder.getName(), fileNames);
              } else {
                  String fileName = (fileEntry.getPath()).toString();
                  fileNames.add(fileEntry.getPath());
              }
          }
      }
      return dirFiles;
  }
  </code></pre>
  
  <p>Please help me find out where am going wrong. </p>
  
  <p><strong><em>Input is the path of the parent directory.</em></strong></p>
  
  <p>Expected Output:  </p>
  
  <pre><code>{"EN" = [File1, File2],  "FR" = [File3, File4], "GE" = [File5, File6]}
  </code></pre>
  
  <p>Thank You.</p>