9. NIO2 Flashcards
What does enum NOFOLLOW_LINKS mean?
If provided, symbolic links when encountered
will not be traversed. Useful for performing
operations on symbolic links themselves rather
than their target.
Test file existing
Read file data
Copy file
Move file
What does enum FOLLOW_LINKS mean?
If provided, symbolic links when encountered
will be traversed.
Traverse a directory tree
What does enum COPY_ATTRIBUTES mean?
If provided, all metadata about a file will be
copied with it.
Copy file
What does enum REPLACE_EXISTING mean?
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
Copy file
Move file
What does enum ATOMIC_MOVE mean?
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 (AtomicMoveNotSupportedException)
Move file
How to get a referance to Path interface?
There’s Paths factory that provides platform specific constructors
Path p = Paths.get(String) or Path p = Paths.get(String, String…)
The second method joins the directories with a platform specific path separator.
Can URI be constructed from relative path?
No, URI always needs an absolute path.
Method that “Returns the string representation of this path.”
String toString()
Returns the string representation of this path.
If this path was created by converting a path string using the getPath method then the path string returned by this method may differ from the original String used to create the path.
The returned path string uses the default name separator to separate names in the path.
Method that “Returns the number of name elements in the path.”
int getNameCount()
Returns the number of name elements in the path.
Returns:
the number of elements in the path, or 0 if this path only represents a root component
Method that “Returns a name element of this path as a Path object.”
Path getName(int index)
Returns a name element of this path as a Path object.
The index parameter is the index of the name element to return. The element that is closest to the root in the directory hierarchy has index 0. The element that is farthest from the root has index count-1.
Parameters:
index - the index of the element
Returns:
the name element
What is the getNameCount() of path representing root?
0
Method that “Returns the name of the file or directory denoted by this path as a Path object.”
Path getFileName()
Returns the name of the file or directory denoted by this path as a Path object. The file name is the farthest element from the root in the directory hierarchy.
Method that “Returns the parent path, or null if this path does not have a parent.”
Path getParent()
Returns the parent path, or null if this path does not have a parent.
The parent of this path object consists of this path’s root component, if any, and each element in the path except for the farthest from the root in the directory hierarchy. This method does not access the file system; the path or its parent may not exist. Furthermore, this method does not eliminate special names such as “.” and “..” that may be used in some implementations. On UNIX for example, the parent of “/a/b/c” is “/a/b”, and the parent of “x/y/.” is “x/y”. This method may be used with the normalize method, to eliminate redundant names, for cases where shell-like navigation is required.
If this path has one or more elements, and no root component, then this method is equivalent to evaluating the expression:
subpath(0, getNameCount()-1);
Returns:
a path representing the path’s parent
Method that “Returns the root component of this path as a Path object, or null if this path does not have a root component.”
Path getRoot()
Returns the root component of this path as a Path object, or null if this path does not have a root component.
If path is relative, it returns null.
Method that “Tells whether or not this path is absolute.”
boolean isAbsolute()
Tells whether or not this path is absolute.
An absolute path is complete in that it doesn’t need to be combined with other path information in order to locate a file.
Returns:
true if, and only if, this path is absolute