import java.io.File; public class IsFile { public static void main(String args[]){ File f = new File("c:\\work\\hello"); isFile(f); } private static void isFile(File f) { if(f.isFile()){ System.out.println("It's a file " + f.getName()); }else{ System.out.println("It's a folder " + f.getName()); for(File file : f.listFiles()){ isFile(file); } } } }