path in Java

The java.nio.file.Path interface is the primary NIO.2 API. A Path object represents a path to a file or directory. The reason why Path is an interface and not a class is that creating a file or directory is considered a file system–dependent task. 
<b>Common Path methods</b>
Method | Meaning
------ | ------
Paths.get(String)<br>Paths.get(String,String...)<br>Paths.get(new URI(String))<br>FileSystems.getDefault().getPath(String) | obtains a Path object using the java.nio.files.Paths factory class. You can use a vararg of type String, or a URI value.
file.toPath() | java.io.File class has a method, toPath(), that operates on an instance File variable. For backward compatibility, the Path interface also contains a method toFile() to return a File instance.
Path.relativize(path) | constructs the relative path from one Path object to another. If both path values are relative, then the relativize() method computes the paths as if they are in the same current working directory. If both path values are absolute, then the method computes the relative path from one absolute location to another, regardless of the current working directory.
Path.resolve(path) | creates a new Path by joining an existing path to the current path. If the name separator is “/” and a path represents “a/b/c”, then invoking this method with the path string “xxx” will result in the Path “a/b/c/xxx”.
Path.resolveSibling(path) | Resolve the given path as parameter against this path’s parent path. Suppose that the name separator is “/” and the caller represents “a/b/c”, then invoking this method with the Path “xxx” will result in the Path “a/b/xxx”. If this caller does not have a parent path or path is absolute, then this method returns path. If path is an empty path then this method returns this caller’s parent, or where this caller doesn’t have a parent, the empty path. This is very useful where a file name needs to be replaced with another file name.
Path.subpath(int,int) | returns a relative subpath of the Path object, referenced by an inclusive start index and an exclusive end index.
Path.normalize() | There are times when relative paths are combined such that there are redundancies in the path value. The Path.normalize() method to eliminate the redundancies in the path
Path.toRealPath() | returns a reference to a real path within the file system.
Path.toAbsolutePath() | The toRealPath() method performs additional steps, such as removing redundant path elements. In other words, it implicitly calls normalize() on the resulting absolute path.

<b>Common optional arguments</b>
Enum Value | Usage | Description
----- | ----- | -----
NOFOLLOW_LINKS | Test file existing<br>Read file data<br>Copy file<br>Move file | If provided, symbolic links when encountered will not be traversed. Useful for performing operations on symbolic links themselves rather than their target.
FOLLOW_LINKS | Traverse a directory tree | If provided, symbolic links when encountered will be traversed.
COPY_ATTRIBUTES | Copy file | If provided, all metadata about a file will be copied with it.
REPLACE_EXISTING | Copy file<br>Move file | If provided and the target file exists, it will be replaced; otherwise, if it is not provided, an exception will be thrown if the file already exists.
ATOMIC_MOVE | Move file | The operation is performed in an atomic manner within the file system, ensuring that any process using the file sees only a complete record. Method using it may throw an exception if the feature is unsupported by the file system.

Many of the same operations available in java.io.File are available to  java.nio.file.Path  via a helper class called java.nio.file.Files. Unlike the methods in the Path and Paths class, most of the options within the Files class will throw an exception if the file to which the Path refers does not exist. 
<b>IO vs NIO.2 </b>
Legacy Method|NIO.2 Method
------ | ------
file.exists() | Files.exists(path)
file.getName() | path.getFileName()
file.getAbsolutePath() | path.toAbsolutePath()
file.isDirectory() | Files.isDirectory(path)
file.isFile() | Files.isRegularFile(path)
file.isHidden() | Files.isHidden(path)
file.length() | Files.size(path)
file.lastModified() | Files.getLastModifiedTime(path)
file.setLastModified(time) | Files.setLastModifiedTime(path,fileTime)
file.delete() | Files.delete(path) 
file.renameTo(otherFile) | Files.move(path,otherPath)
file.mkdir() | Files.createDirectory(path)
file.mkdirs() | Files.createDirectories(path)
file.listFiles() | Files.list(path)