

The method java.io.File.isDirectory() checks whether the file is a directory or not and the boolean value that is returned by the method is printed. getParent() method is used to get the path of a folder it will return the exact path of the folder where the file exists. File file new File ('C:' + parator + 'jdk11.0.2' + parator, 'demo1.java') ('The absolute path name is: ' + file. A code snippet that demonstrates this is given as follows. In this tutorial, we'll learn how to get the current working directory in Java with, java.io.File,, and. The output of the above program is as follows − Output Is directory? false The absolute pathname of the file is obtained using the method java.io.File.getAbsolutePath () in the form of a string and is printed. It's an easy task to get the current working directory in Java, but unfortunately, there's no direct API available in the JDK to do this. For Example: if we create a file object using the path as program.txt, it points to the file present in the. This function returns the absolute pathname of the given file object.If the pathname of the file object is absolute then it simply returns the path of the current file object. File file new Path currentDirectoryPath Paths.get FileSystem fileSystem. This method returns true if the file specified by the abstract path name is a directory and false otherwise.Ī program that demonstrates this is given as follows − Example The getAbsolutePath () method is a part of File class. // create file object for current folder.


The method java.io.File.isDirectory() checks whether a file with the specified abstract path name is a directory or not.
