Chapter 9: NIO 2 Flashcards
can be used to get the operating system-dependent file separator from the JVM.
System.getProperty(“path.separator”)
optional arguments in NIO.2,If provided, symbolic links when encountered will not be traversed. Useful for performing operations on symbolic links themselves rather than their target.
NOFOLLOW_LINKS
optional arguments in NIO.2, If provided, symbolic links when encountered will be traversed.
FOLLOW_LINKS
optional arguments in NIO.2, If provided, all metadata about a file will be copied with it.
COPY_ATTRIBUTES
optional arguments in NIO.2, 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.
REPLACE_EXISTING
optional arguments in NIO.2, 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.
ATOMIC_MOVE
Path method, returns a String representation of the entire path.
Path.toString()
Path method, retrieve the number of elements in the path
Path.getNameCount() int
Path method, retrieve a reference to each element,
Path.getName(int i) - returns Path
Path method, returns a Path instance representing the filename, which is the farthest element from the root
Path.getFileName - returns Path
Path method, returns a Path instance representing the parent path or null if there is no such parent
Path.getParent() - returns Path
Path method, returns the root element for the Path object or null if the Path object is relative.
Path.getRoot() - returns Path
Path method, returns true if the path the object references is absolute and false if the path the object references is relative.
isAbsolute()
Path method, converts a relative Path object to an absolute Path object by joining it to the current working directory
toAbsolutePath()
Path method, returns a relative subpath of the Path object
Path.subpath(int, int) - returns Path,
Inclusive beginning index, exclusive end index
Path method, for constructing the relative path from one Path object to another.
Path.relativize(path2) - result is path of path2 in relation to this path.
Path method, for method for creating a new Path by joining an existing path to the current path.
Path.resolve(Path 2)
Path method, method to eliminate the redundancies in the path.
Path.normalize()
Path method, method takes a Path object that may or may not point to an existing file within the file system, and it returns a reference to a real path within the file system.
Path.toRealPath() - returns Path
Path method, use the toRealPath() method to gain access to the current working directory
Paths.get(“.”).toRealPath()
Files method, method takes a Path object and returns true if, and only if, it references a file that exists in the file system.
Files.exists(Path p)
Files method, method is useful for determining if two Path objects relate to the same file within the file system
Files.isSameFile(Path p, Path p2)
returns true immediately when the two paths passes equals method.
throws IOException when the file does not exist.
Files method, method to create a directory
Files.createDirectory - throws IOException when the parent directory does not exist or when the directory already exists or cannot be created.
Files.createDirectories()
Files method, which copies a file or directory from one location to another.
Files.copy(Path p1, Path p2) - throws IOException when file does not exist or cannot be read.