 <p>You can use <a href="http://docs.oracle.com/javase/7/docs/api/java/io/File.html#isDirectory%28%29" rel="nofollow"><code>File.isDirectory()</code></a> to test <em>whether the file denoted by this abstract pathname is a directory.</em> You can also use <a href="http://docs.oracle.com/javase/7/docs/api/java/io/File.html#isFile%28%29" rel="nofollow"><code>File.isFile()</code></a> to test <em>whether the file denoted by this abstract pathname is a <strong>normal</strong> file. A file is normal if it is not a directory and, in addition, satisfies other system-dependent criteria.</em></p> <pre><code>File f = new File(fileName); if (f.isFile()) { // it's a file. } else if (f.isDirectory()) { // it's a directory. } </code></pre>