title: Java File.exists() versus File.isFile()
body: <p>I'm unable to think of a realistic use case for the method <a href="http://docs.oracle.com/javase/7/docs/api/java/io/File.html#exists()" rel="noreferrer"><code>java.io.File.exists()</code></a> or its equivalent in Java 7 <a href="http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#exists(java.nio.file.Path,%20java.nio.file.LinkOption...)" rel="noreferrer"><code>java.nio.file.Files.exists(Path)</code></a>. It seems that <code>isFile()</code> or <code>isDirectory()</code> would be preferable in all cases (or <code>canRead()</code>, <code>canWrite()</code>, etc.).</p>
  
  <p>For example, in <a href="https://stackoverflow.com/questions/1816673/how-do-i-check-if-a-file-exists-java-on-windows">How do I check if a file exists in Java?</a>, the accepted answer seems silly, as the second answer points out.</p>
  
  <p>Can anyone give an example where it's useful to know that a thing exists, <em>without</em> knowing whether the thing is a file or directory?</p>
  
  <p>EDIT: I understand what <code>File.exists()</code> does. My question is, <strong>when</strong> would that functionality ever help someone? I'm searching for an example like, "Use <code>File.exists()</code> when _ _ _ _ _ _, because neither <code>File.isFile()</code> nor <code>File.isDirectory()</code> add any value in that case."</p>
  
  <hr>
  
  <p>In retrospect, I think my confusion here was regarding two seemingly contradictory statements in the JavaDoc of the <code>File</code> class. The first sentence defines the class as,</p>
  
  <blockquote>
    <p>An abstract representation of file and directory pathnames.</p>
  </blockquote>
  
  <p>That sounds like a clear dichotomy; but further in, the doc counters it with,</p>
  
  <blockquote>
    <p>Instances of this class may or may not denote an actual file-system object such as a file or a directory.</p>
  </blockquote>
  
  <p>I think an example of a third file-system object would have helped immensely in the documentation; but that category seems to lack even a name, resulting in the awkward phrasing of the JavaDoc for the <code>Files</code> class: a collection of static methods,</p>
  
  <blockquote>
    <p>that operate on files, directories, or other types of files.</p>
  </blockquote>
  
  <p>In the accepted answer, @koral refers to these other types as "special files". That seems apt to me. They are so special, I didn't know they existed. </p>