Java File I/O (NIO.2) Flashcards
Which Path method is used to append a partial path to an existing Path object?
resolve
Which interface should you implement to filter files based on criteria other than the file name?
DirectoryStream.Filter
Which element will be retrieved from the path C:\paul\young\java7\804.java when executing the method getName(1)?
young
Remember base zero.
Which StandardWatchEventKinds event type indicates that a directory entry has been newly created or an existing entry has been renamed?
ENTRY_CREATE
What are the four StandardWatchEventKinds?
ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY, and OVERFLOW
Which StandardWatchEventKinds event is used to indicate that events may have been lost or discarded?
OVERFLOW
Which StandardWatchEventKinds event is used to indicate that a directory entry has been deleted or renamed out of the directory?
ENTRY_DELETE
Which StandardWatchEventKinds event is used to indicate that a directory entry has been modified?
ENTRY_MODIFY
Which StandardOpenOption enumeration value will only synchronize file content with the underlying drive?
DSYNC
What is the signature for the method PathMatcher.matches?
It accepts a Path argument and returns a Boolean value indicating whether there is a match.
Which FileSystem method accepts a string that supports either regular expressions or glob patterns?
getPathMatcher
What is a glob pattern?
An optional string to limit the returned entries to those that match.
Which StandardWatchEventKinds event type indicates that a directory entry has been deleted or an existing entry has been renamed outside the directory?
ENTRY_DELETE
Which exception is thrown if a path string cannot be converted to a Path object?
InvalidPathException
Which Path method converts .. and . into the syntactic directory locations so that only the named elements are contained in the Path object?
normalize
Which Path method converts a relative Path object into an absolute Path object?
toAbsolutePath
Which Path method is used to determine the relative path between two Path objects?
relativize
Which StandardOpenOption enumeration value will synchronize both file content and metadata with the underlying drive?
SYNC
Which StandardOpenOption enumeration value will create a file or open the existing file if it already exists?
CREATE
Which BasicFileAttributeView subinterface supports the legacy attributes archive, hidden, readonly, and system?
DosFileAttributeView
Which BasicFileAttributeView subinterface adds the attribute owner?
FileOwnerAttributeView
Which two FileVisitResult values when returned from the preVisitDirectory method will NOT visit file and directory entries?
SKIP_SUBTREE or SKIP_SIBLINGS
For a Path object, what does p1.relativize(p2) return?
The relative path from p1 to p2.
For a Path object, what does p.normalize() return?
Returns a path that is this path with redundant name elements (ie . .. ) eliminated.
For a Path object, what does p1.resolve(p2) return?
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.
For a Path object, what does p1.resolveSibling(p2) return?
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.
What are the file copy signatures defined in the Files class?
copy(InputStream, Path, CopyOption(s))
copy(Path,InputStream)
copy(Path, Path, CopyOption(s))
What are the file move signatures defined in the Files class?
move(Path, Path, CopyOption(s))
The newDirectoryStream method is defined in what class?
Files
What is newDirectoryStream method used for?
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.
newDirectoryStream(T1 arg1, T2 arg2) What is arg1 and arg2
arg1 = the path to the directory arg2 = the glob pattern
newDirectoryStream is in the Files class.
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?
poll
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?
FileSystemNotFoundException
Which StandardWatchEventKinds event type indicates an event has been lost or discarded?
OVERFLOW
Which WatchService method retrieves and removes the next watch key, but waits if no watch keys are in the queue?
take
In a glob pattern, what does the asterisk character match?
Zero or more characters
Which StandardOpenOption enumeration value will begin writing data to the beginning of the file?
WRITE
Which StandardOpenOption enumeration value reduces the file contents to zero bytes before any write operations?
TRUNCATE_EXISTING
Which StandardWatchEventKinds event type indicates that a directory entry has had its content or metadata modified?
ENTRY_MODIFY
Which interface represents a hierarchical structure of folder and/or file elements?
Path
Which exception is thrown if a specified provider is not installed when a URI is used to create a Path object?
FileSystemNotFoundException
Which FileVisitor method is invoked after its file and directory entries are visited?
postVisitDirectory
What are the four key FileVisitor methods?
postVisitDirectory, preVisitDirectory, visitFile, visitFileFailed
Which interface should you implement to evaluate whether a Path matches a preset criteria?
PathMatcher
Which WatchService method ends the watch service?
close
Which element will be retrieved from the path C:\paul\worker\java7\804.java when executing the method getName(3)?
804.java
In a glob pattern, what do the curly braces {} contain?
A comma-delimited list of subpatterns
Which BasicFileAttributeView subinterface supports the attributes group and permissions?
PosixFileAttributeView
Which BasicFileAttributeView subinterface supports allowing or disallowing permissions on file system objects for a specified identity other than the owner?
AclFileAttributeView
Which FileVisitor method is invoked for each file when it is visited?
visitFile
Which FileVisitResult value, when returned from the preVisitDirectory method, will visit file and directory entries?
CONTINUE
Describe the Files.move method?
Files.move(src File, dest File, options) note the it is source file dest file and NOT source file and dest directory.
What happens if Files.move is used and the file exists in the desination directory.
A FileAlreadyExistsException exception will be thrown if option REPLACE_EXISTING is not used.