Chapter 9: NIO 2 Flashcards

1
Q

can be used to get the operating system-dependent file separator from the JVM.

A

System.getProperty(“path.separator”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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.

A

NOFOLLOW_LINKS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

optional arguments in NIO.2, If provided, symbolic links when encountered will be traversed.

A

FOLLOW_LINKS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

optional arguments in NIO.2, If provided, all metadata about a file will be copied with it.

A

COPY_ATTRIBUTES

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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.

A

REPLACE_EXISTING

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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.

A

ATOMIC_MOVE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Path method, returns a String representation of the entire path.

A

Path.toString()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Path method, retrieve the number of elements in the path

A

Path.getNameCount() int

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Path method, retrieve a reference to each element,

A

Path.getName(int i) - returns Path

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Path method, returns a Path instance representing the filename, which is the farthest element from the root

A

Path.getFileName - returns Path

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Path method, returns a Path instance representing the parent path or null if there is no such parent

A

Path.getParent() - returns Path

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Path method, returns the root element for the Path object or null if the Path object is relative.

A

Path.getRoot() - returns Path

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Path method, returns true if the path the object references is absolute and false if the path the object references is relative.

A

isAbsolute()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Path method, converts a relative Path object to an absolute Path object by joining it to the current working directory

A

toAbsolutePath()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Path method, returns a relative subpath of the Path object

A

Path.subpath(int, int) - returns Path,

Inclusive beginning index, exclusive end index

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Path method, for constructing the relative path from one Path object to another.

A

Path.relativize(path2) - result is path of path2 in relation to this path.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Path method, for method for creating a new Path by joining an existing path to the current path.

A

Path.resolve(Path 2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Path method, method to eliminate the redundancies in the path.

A

Path.normalize()

19
Q

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.

A

Path.toRealPath() - returns Path

20
Q

Path method, use the toRealPath() method to gain access to the current working directory

A

Paths.get(“.”).toRealPath()

21
Q

Files method, method takes a Path object and returns true if, and only if, it references a file that exists in the file system.

A

Files.exists(Path p)

22
Q

Files method, method is useful for determining if two Path objects relate to the same file within the file system

A

Files.isSameFile(Path p, Path p2)

returns true immediately when the two paths passes equals method.
throws IOException when the file does not exist.

23
Q

Files method, method to create a directory

A

Files.createDirectory - throws IOException when the parent directory does not exist or when the directory already exists or cannot be created.

Files.createDirectories()

24
Q

Files method, which copies a file or directory from one location to another.

A

Files.copy(Path p1, Path p2) - throws IOException when file does not exist or cannot be read.

25
Q

Files method, two overloaded copy methods.

A

Files.copy(InputStream is, Path p);

Files.cop(Path p, OutputStream s);

26
Q

Files method, moves or renames a file or directory within the file system.

A

Files.move(Path p, Path p) - throws IOException when the file or directory cannot be found.

27
Q

Files method, method deletes a file or empty directory within the file system.

A

Files.delete(Path p) throws the checked IOException under variety of circumstances.

28
Q

Files method, method is identical to the delete(Path) method, except that it will not throw an exception if the file or directory does not exist, but instead it will return a boolean value of false.

A

Files.deleteIfExists(Path p) throws

29
Q

Files method, writes to a file specified at the Path location using a BufferedWriter.

A

Files.newBufferedWriter(Path p, CharacterSet cs)

30
Q

Files method, reads the file specified at the Path location using a java.io.BufferedReader object

A

Files.newBufferedReader(Path p, CharacterSet cs)

31
Q

Files method, method reads all of the lines of a text file and returns the results as an ordered List of String values

A

Files.readAllLines()

32
Q

Files method, three methods for determining if a path refers to a directory, a regular file, or a symbolic link.

A

Files.isRegularFile(Path p), - true if path is a file or symbolic link to the file.

Files.isDirectory(Path p), - returns true if directory or symbolic link to directory.

Files.isSymbolicLink(Path p) - true if symbolic link

33
Q

Files method, method to determine whether a file or directory is hidden within the file system.

A

Files.isHidden(Path p)

34
Q

Files method, returns true if file exists and its contents are readable, based on the permission rules of the underlying file system.

A

Files.isReadable(Path p), does not throw exception if file does not exist but rather return false.

35
Q

Files method, returns true file is marked executable within the file system.

A

Files.isExecutable(Path p), does not throw exception if file does not exist but rather return false.

36
Q

Files method, method is used to determine the size of the file in bytes.

A

Files.size(Path p) throws IOException when the file does not exist

37
Q

Files method, returns a FileTime object, code reads and outputs the last-modified time value of

A

Files.getLastModifiedTime(Path p)

.toMillis() to get the epoch

38
Q

Files method, returns a FileTime object, set the last-modified time value of file

A

Files.setLastModifiedTime(Path p, FileTime ft)

39
Q

Files method, getting the owner and setting the owner

A

Files.setOwner(Path p, UserPrincipal owner)
Files.getOwner(Path p);

UserPrincipal owner = FileSystems.getDefault().getUserPrincipalLookUpService().lookUpPrincipal(“name”)

40
Q

Files method, returns a read-only view of the file attributes.

A

FIles.readAttributes(Path p, BasicFileAttributes.class) -> returns BasicFileAttribute

41
Q

Files method, returns the underlying attribute view, and it provides a direct resource for modifying file information.

A

Files.getFileAttributeView(Path, BasicFileAttributes.class)

42
Q

BasicFileAttributesView method for updating the time.

A

setTimes(FileTime lastModifiedTime, FileTime lastAccessTime, FileTime createTime)

43
Q

Files method, method behaves in a similar manner as the Files.walk() method, except that it requires the depth value to be explicitly set along with a BiPredicate to filter the data.

A

Files.find(Path,int,BiPredicate) - > Stream

parameter depth and biPredicate(Path, BasicFileAttributes).