Java File Class
What java.io.File Is
java.io.File is Java's original class for working with file and folder paths and performing basic file-system operations. It has existed since Java 1.0, so you'll find it throughout older code, many libraries, and APIs such as FileReader, FileInputStream, ProcessBuilder.directory() and Swing's JFileChooser.
Despite its name, a File object is not a file and doesn't hold any content. It's an abstract representation of a path — exactly like java.nio.file.Path. Creating new File("report.pdf") doesn't create anything on disk, and the file doesn't need to exist. Methods such as exists(), length() or delete() are what actually ask the operating system about, or change, the file at that location.
Since Java 7, Path and Files are the recommended API for new code, because File has several design problems (covered below). Still, you need to understand File to read and maintain existing code and to work with APIs that require it.
Creating File Objects
File a = new File("course-data/lessons.txt"); // a path string
File b = new File("course-data", "lessons.txt"); // parent string + child name
File c = new File(new File("course-data"), "lessons.txt"); // parent File + child name
File d = Path.of("course-data", "lessons.txt").toFile(); // from a Path
The two-argument constructors join the parent and child with the platform separator (/ or