title: Java Path exception
body: <p>So, I used java.io.File for basically everything before.
  But now, when switching to java.nio.Path, I'm experiencing a few problems...</p>
  
  <p>What I use it for is basically loading/saving files, on my program startup and shutdown.</p>
  
  <p>I use it in multiple places but I'll type an example:</p>
  
  <pre><code>  Objects.requireNonNull(directory, "directory");
  
      if (this.myObjectMap.isEmpty()) {
          return;
      }
  
      Files.list(directory).forEach(file -&gt; {
          try {
              Files.deleteIfExists(file);
          } catch (IOException exception) {
              exception.printStackTrace();
          }
      });
  
      Files.createDirectories(directory);
  
      for (Object object : this.myObjectMap.values()) {
          Path destination = directory.resolve(object.toString() + ".json");
  
          Files.deleteIfExists(destination);
          Files.createFile(destination);
  
          JsonObject properties = new JsonObject();
  
          JSONFileHandler.save(destination, properties);
      }
  </code></pre>
  
  <p>My problem is that everytime I do something similar to this, it throws a NoSuchFileException exception before even using the Path... But I don't know what I'm doing wrong, since I check if it exists after creating the Path.</p>
  
  <p><strong>Update</strong></p>
  
  <p>The exception stacktrace is the following:</p>
  
  <pre><code>java.nio.file.NoSuchFileException: **the directory**
  
  at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:79)
  at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
  at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
  at sun.nio.fs.WindowsDirectoryStream.&lt;init&gt;(WindowsDirectoryStream.java:86)
  at sun.nio.fs.WindowsFileSystemProvider.newDirectoryStream(WindowsFileSystemProvider.java:518)
  at java.nio.file.Files.newDirectoryStream(Files.java:457)
  at java.nio.file.Files.list(Files.java:3451)
  </code></pre>