Path filePath = Paths.get("C:/myFolder/myFile.txt"); if(Files.isRegularFile(filePath)) { System.out.println("This file is a regular file."); } else { System.out.println("This file is not a regular file."); }
Path dirPath = Paths.get("C:/myFolder"); if(Files.isRegularFile(dirPath)) { System.out.println("This directory is a regular file."); } else { System.out.println("This directory is not a regular file."); }The Files class is part of the Java NIO (New Input/Output) package library.