 <p>What is the problem with this code? only one curly braces i found is missing else it is working fine.</p> <p>This will create a dir test in c drive if does not exist else it will list the files in test dir over n over again</p> <pre><code>String entitiesFolderDirectory = "C:\\test"; File entitiesFolder = new File(entitiesFolderDirectory); try { List&lt;String&gt; entitiesDirectoryContents = Arrays.asList(entitiesFolder.list()); for (String entityPropertiesFileName : entitiesDirectoryContents) { System.out.println(entityPropertiesFileName); } }catch (NullPointerException e) { System.out.println("creating new folder"); entitiesFolder.mkdirs(); } </code></pre>