Java File Name Printing <p>I am trying to print name of files from two folders, and this code compiles but not giving anything on running it.</p> <p>The main target here is to find common name files in two folders, I have stored file names in two arrays and then i will applying sorting and will find common files.</p> <pre><code> package javaapplication13; import java.io.File; import java.util.*; public class ListFiles1 { public static void main(String[] args) { String path1 = "C:/"; String path2 = "D:/"; File folder1 = new File(path1); File folder2 = new File(path2); String[] f1=folder1.list(); File[] listOfFiles1 = folder1.listFiles(); File[] listOfFiles2 = folder2.listFiles(); ArrayList&lt;String&gt; fileNames1 = new ArrayList&lt;&gt;(); ArrayList&lt;String&gt; fileNames2 = new ArrayList&lt;&gt;(); for (int i = 0; i &lt; listOfFiles1.length; i++) { if (listOfFiles1[i].isFile()) { fileNames1.add(listOfFiles1[i].getName());//wow System.out.println(listOfFiles1[i].getName()); } } for (int i = 0; i &lt; listOfFiles2.length; i++) { if (listOfFiles2[i].isFile()) { fileNames2.add(listOfFiles2[i].getName());//seriously wow } } } } </code></pre>