Java File I/O (NIO.2) Flashcards

1
Q

Which Path method is used to append a partial path to an existing Path object?

A

resolve

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

Which interface should you implement to filter files based on criteria other than the file name?

A

DirectoryStream.Filter

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

Which element will be retrieved from the path C:\paul\young\java7\804.java when executing the method getName(1)?

A

young

Remember base zero.

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

Which StandardWatchEventKinds event type indicates that a directory entry has been newly created or an existing entry has been renamed?

A

ENTRY_CREATE

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

What are the four StandardWatchEventKinds?

A

ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY, and OVERFLOW

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

Which StandardWatchEventKinds event is used to indicate that events may have been lost or discarded?

A

OVERFLOW

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

Which StandardWatchEventKinds event is used to indicate that a directory entry has been deleted or renamed out of the directory?

A

ENTRY_DELETE

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

Which StandardWatchEventKinds event is used to indicate that a directory entry has been modified?

A

ENTRY_MODIFY

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

Which StandardOpenOption enumeration value will only synchronize file content with the underlying drive?

A

DSYNC

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

What is the signature for the method PathMatcher.matches?

A

It accepts a Path argument and returns a Boolean value indicating whether there is a match.

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

Which FileSystem method accepts a string that supports either regular expressions or glob patterns?

A

getPathMatcher

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

What is a glob pattern?

A

An optional string to limit the returned entries to those that match.

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

Which StandardWatchEventKinds event type indicates that a directory entry has been deleted or an existing entry has been renamed outside the directory?

A

ENTRY_DELETE

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

Which exception is thrown if a path string cannot be converted to a Path object?

A

InvalidPathException

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

Which Path method converts .. and . into the syntactic directory locations so that only the named elements are contained in the Path object?

A

normalize

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

Which Path method converts a relative Path object into an absolute Path object?

A

toAbsolutePath

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

Which Path method is used to determine the relative path between two Path objects?

A

relativize

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

Which StandardOpenOption enumeration value will synchronize both file content and metadata with the underlying drive?

A

SYNC

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

Which StandardOpenOption enumeration value will create a file or open the existing file if it already exists?

A

CREATE

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

Which BasicFileAttributeView subinterface supports the legacy attributes archive, hidden, readonly, and system?

A

DosFileAttributeView

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

Which BasicFileAttributeView subinterface adds the attribute owner?

A

FileOwnerAttributeView

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

Which two FileVisitResult values when returned from the preVisitDirectory method will NOT visit file and directory entries?

A

SKIP_SUBTREE or SKIP_SIBLINGS

23
Q

For a Path object, what does p1.relativize(p2) return?

A

The relative path from p1 to p2.

24
Q

For a Path object, what does p.normalize() return?

A

Returns a path that is this path with redundant name elements (ie . .. ) eliminated.

25
Q

For a Path object, what does p1.resolve(p2) return?

A

If the p2 is an absolute path then this method trivially returns p2. If p2 is an empty path then this method trivially returns this p1. Otherwise this method considers this path to be a directory and resolves the given path against this path. In the simplest case, the given path does not have a root component, in which case this method joins the given path to this path and returns a resulting path that ends with the given path.

26
Q

For a Path object, what does p1.resolveSibling(p2) return?

A

Resolves p2 against p1’s parent path. If p2 is an empty path then this method returns p1’s parent, or where this p1 doesn’t have a parent, the empty path.

27
Q

What are the file copy signatures defined in the Files class?

A

copy(InputStream, Path, CopyOption(s))
copy(Path,InputStream)
copy(Path, Path, CopyOption(s))

28
Q

What are the file move signatures defined in the Files class?

A

move(Path, Path, CopyOption(s))

29
Q

The newDirectoryStream method is defined in what class?

A

Files

30
Q

What is newDirectoryStream method used for?

A

newDirectoryStream is located in the Files class and is used to open a directory, returning a DirectoryStream to iterate over all entries in the directory.

31
Q
newDirectoryStream(T1 arg1, T2 arg2)  
What is arg1 and arg2
A
arg1 = the path to the directory
arg2 = the glob pattern

newDirectoryStream is in the Files class.

32
Q

Which WatchService method retrieves and removes the next watch key, but returns null if no watch keys are in the queue, optionally after a specified wait time?

A

poll

33
Q

Which exception is thrown if the file system does not exist and cannot be created automatically when a URI is used to create a Path object?

A

FileSystemNotFoundException

34
Q

Which StandardWatchEventKinds event type indicates an event has been lost or discarded?

A

OVERFLOW

35
Q

Which WatchService method retrieves and removes the next watch key, but waits if no watch keys are in the queue?

A

take

36
Q

In a glob pattern, what does the asterisk character match?

A

Zero or more characters

37
Q

Which StandardOpenOption enumeration value will begin writing data to the beginning of the file?

A

WRITE

38
Q

Which StandardOpenOption enumeration value reduces the file contents to zero bytes before any write operations?

A

TRUNCATE_EXISTING

39
Q

Which StandardWatchEventKinds event type indicates that a directory entry has had its content or metadata modified?

A

ENTRY_MODIFY

40
Q

Which interface represents a hierarchical structure of folder and/or file elements?

A

Path

41
Q

Which exception is thrown if a specified provider is not installed when a URI is used to create a Path object?

A

FileSystemNotFoundException

42
Q

Which FileVisitor method is invoked after its file and directory entries are visited?

A

postVisitDirectory

43
Q

What are the four key FileVisitor methods?

A

postVisitDirectory, preVisitDirectory, visitFile, visitFileFailed

44
Q

Which interface should you implement to evaluate whether a Path matches a preset criteria?

A

PathMatcher

45
Q

Which WatchService method ends the watch service?

A

close

46
Q

Which element will be retrieved from the path C:\paul\worker\java7\804.java when executing the method getName(3)?

A

804.java

47
Q

In a glob pattern, what do the curly braces {} contain?

A

A comma-delimited list of subpatterns

48
Q

Which BasicFileAttributeView subinterface supports the attributes group and permissions?

A

PosixFileAttributeView

49
Q

Which BasicFileAttributeView subinterface supports allowing or disallowing permissions on file system objects for a specified identity other than the owner?

A

AclFileAttributeView

50
Q

Which FileVisitor method is invoked for each file when it is visited?

A

visitFile

51
Q

Which FileVisitResult value, when returned from the preVisitDirectory method, will visit file and directory entries?

A

CONTINUE

52
Q

Describe the Files.move method?

A

Files.move(src File, dest File, options) note the it is source file dest file and NOT source file and dest directory.

53
Q

What happens if Files.move is used and the file exists in the desination directory.

A

A FileAlreadyExistsException exception will be thrown if option REPLACE_EXISTING is not used.