Path and File Object Methods Flashcards
How to create a Path object?
Path.get(“”);
Path method for returning a File object
Path.toFile();
Path method for returning URI object
Path.toURI();
Path.getPath() is a shorthand for the class?
java.nio.file.FileSystem.getPath()
Medhod of File object to get Path object
File.getPath()
Path method for getting the number of elements in path and a reference to each element.
Path.getNameCount()
Path method for getting the element name. Returns a Path object.
Path.getName()
Path method for checking if the Path object is absolute. Returns boolean.
Path.absolute()
Path method for converting the relative Path object to absolute. Returns Path object
Path.toAbsolute();
Path method for getting Path object representing the filename
Path.getFileName()
Path method for getting Path object representing the parent path.
Path.getParent()
Path method for getting the root path object.
Path.getPath();
Path method which returns relative path referenced by inclusive start index and exclusive end index
Path.subpath(, )
Path method for constructing a relative path from one Path object to another
Path.relativize();
Path path3 = Paths.get(“E:\habitat”);
Path path4 = Paths.get(“E:\sanctuary\raven”);
System.out.println(path3.relativize(path4));
System.out.println(path4.relativize(path3));
..\sanctuary\raven
....\habitat
Both has to be relative. or both has to be absolute.
method for creating a new Path by joining the existing path to the current path
Path.resolve()
There are times that the resulting Path of relativize method contains redundant path. This path method cleans up the path
Path.normalize()
Path object may point to non-existent file. This method talkes a path object and returns a real Path.
object.
Converts relative path to absolute Path.
Calls normalize implicitly.
Path.toRealPath();