title: java File mkdirs and createNewFile won't work
body: <p>I'm trying to copy and existing directory structure (no need for the file contents themselves, 0 length dummy files will do). However <code>mkdirs()</code> won't create the necessary directories, causing <code>file.createNewFile()</code> to throw an <code>IOException</code>. The code is:</p>
  
  <pre><code>private static void readAndCopy(File fileToCopy) throws IOException {
      File localVersion = new File(fileToCopy.getCanonicalPath().replace("O:\\", "C:\\xfer\\"));
      System.out.println("Replicating " + fileToCopy.getCanonicalPath() + " to " + localVersion.getCanonicalPath());
  
      if (fileToCopy.isDirectory()) {
          boolean dirCreated = localVersion.getParentFile().mkdirs();
          System.out.println(localVersion.getCanonicalPath() + " " + (dirCreated ? "" : "not ") + "created");
  
          if (dirCreated) {
              for (File content : fileToCopy.listFiles()) {
                  readAndCopy(content);
              }
          }
  
      } else {
          if (!localVersion.exists()) {
              localVersion.createNewFile();
          }
      }
  }
  
  public static void main(String[] args) throws IOException {
      readAndCopy(new File("o:\\MY_SRC_DIR"));
  }
  </code></pre>
  
  <p>The error message is:</p>
  
  <pre><code>java.io.IOException: The system cannot find the path specified
      at java.io.WinNTFileSystem.createFileExclusively(Native Method)
      at java.io.File.createNewFile(Unknown Source)
  </code></pre>
  
  <p>I also tried</p>
  
  <pre><code>File origParentFile = fileToCopy.getParentFile();
  File newParent = new File(origParentFile.getCanonicalPath().replace("O:\\", "C:\\xfer\\"));
  localVersion = new File(newParent, fileToCopy.getName());
  </code></pre>
  
  <p>, but that didn't work either.</p>