title: Using File I/O to traverse directory in windows
body: <p>I'm writing a program that uses File I/O to traverse through a directory given by the user and then adds the directories to a generic linked list. The program I wrote works perfectly on Ubuntu, but does not work when I try to use it on Windows. Its a pretty long program but this is the part that I think is having issues:</p>
  
  <pre><code>private Node&lt;Item&gt; currentNode = new Node&lt;Item&gt;();
  
  public void traverse(File fileObject)
  {
      File allFiles[] = fileObject.listFiles();
  
      for(File aFile: allFiles){
          System.out.println(aFile.getName()); /* debugging */
          recursiveTraversal(aFile); /* Line 34 */
      }
  }
  
  
  public void recursiveTraversal(File fileObject){
      Node&lt;Item&gt; newNode = new Node&lt;Item&gt;();
      currentNode.addChild(newNode);
      currentNode = newNode;
      if (fileObject.isDirectory()){
          newNode.setData(new Item());
  
          File allFiles[] = fileObject.listFiles();
          for(File aFile : allFiles){ /* This is line 48 */
              recursiveTraversal(aFile);
          }            
  
      }else if (fileObject.isFile()){
          newNode.setData(new Item());
      }           
      currentNode = newNode.getParent();
  }
  </code></pre>
  
  <p>When I use it on Linux I can give it something like <code>/home/matt/Documents</code> and it works, but when I try on windows using <code>G:\\Users\\Matt\\Documents</code> it errors out. The print statement I threw in actually prints out files in the folder, but something with the rest of the program messes up:</p>
  
  <pre><code>java.lang.NullPointerException
  at FileTraverse.recursiveTraversal(FileTraverse.java:48)
  at FileTraverse.traverse(FileTraverse.java:34)
  at DirectoryMain$ClickAction.actionPerformed(DirectoryMain.java:103)
      ...
  </code></pre>
  
  <p>Theres a lot of errors afterwards that have to do with the Swing GUI this program is running off of but I don't think that has to do with anything. </p>
  
  <p>EDIT: Added in line numbers that correspond with the trace. </p>