title: Why does 'File.exists' return true, even though 'Files.exists' in the NIO 'Files' class returns false
body: <p>I am trying to determine if a file exists in a network folder:</p>
  <pre><code>// File name is &quot;\\QWERTY\folder\dir\A123456.TXT&quot;
  Path path = Paths.get(&quot;\\\\QWERTY\\folder\\dir\\A123456.TXT&quot;)
  </code></pre>
  <p>Using NIO <code>Files</code>:</p>
  <pre><code>Files.exists(path) == false
  </code></pre>
  <p>Using <code>File</code>:</p>
  <pre><code>path.toFile().exists() == true
  </code></pre>
  <p>Using <code>File</code> seems to be the correct one according to our tests. Why does <code>File</code> work better than <code>Files</code>?</p>
  <p>So, which is it? Can't be both!</p>
  <p>But wait, there is also <code>Files.notExists(path)</code>.</p>
  <p><strong>When the network share file actually exists</strong></p>
  <pre><code>Files.exists(path): false
  Files.notExists(path): false
  path.toFile().exists(): true
  </code></pre>
  <p><strong>When the network share file actually does <em>not</em> exist</strong></p>
  <pre><code>Files.exists(path): false
  Files.notExists(path): true
  path.toFile().exists(): false
  </code></pre>
  <p><strong>Another equally insane way of looking at the three results above</strong></p>
  <pre><code>boolean exists = Files.exists(path) || !Files.notExists(path)
  boolean notExists = Files.notExists(path) || !Files.exists(path)
  boolean oldFashionedExists = path.toFile().exists()
  </code></pre>
  <p>:smileyFace:</p>
  <p><strong>Environment and Comments</strong></p>
  <p>The program is running on a Windows 8.1 Pro 32 bit machine (OS and machine) and checking on a network share from a Windows 2008 R2 (32 bit) machine.</p>
  <p>To determine that Files.exists was failed, I installed a WatchService to monitor the folder and saw that the file did exist when Files.exists was checking. I then logged as both methods and found File.exists to be the correct one.</p>
  <p>Now, in my code I have the check as <code>Files.exists(path) || path.toFile().exists()</code>.</p>
  <p>Kinda seems stupid to have to do both. Probably could just get away with the later. Just trying to give the engineers over at Oracle the benefit of the doubt, but the whole thing is rather silly that they report different.</p>
  <p>Also, I don't care if 'exists' is immediately outdated. I just want to know if the file exists at the instant that we are checking. I've never come across this -- we just spent 30 hours between me and another developer trying to figure out why our programs are not interfacing because of this 'feature'.</p>
  <p><strong>Meditate on this a while</strong></p>
  <blockquote>
  <p>File.exists(): Returns true <em><strong>if and only if the file or directory denoted by this abstract pathname exists</strong></em>; false otherwise.</p>
  <p>Files.exists(): Returns true if the file exists; false if the file does not exist <em><strong>or its existence cannot be determined.</strong></em></p>
  </blockquote>
  <p>That cracks me up! &quot;if and only if the file or directory denoted by this abstract pathname exists; false otherwise&quot; is at odds with &quot;true if the file exists; false if the file does not exist or its existence cannot be determined&quot;</p>
  <p>So, how still can <code>File.exists</code> be true if &quot;the existence cannot be determined&quot;? Obviously, the existence can be (and is being) determined by File but not by Files.</p>