Path Interface Flashcards Preview

OCP > Path Interface > Flashcards

Flashcards in Path Interface Deck (16):
1

Returns a path object representing the root of the given path, or null if the path does not have a root.

Path getRoot()

2

Returns the file name or directory name of the given path. Note that the file/directory name is the last element or name in the given path.

Path getFileName()

3

Returns the path object representing the parent of the given path, or null if no parent component exists for the path.

Path getParent()

4

Returns the number of file/directory names in the given path; returns 0 if the given path represents the root.

int getNameCount()

5

Returns the i^th file/directory name; the index 0 starts from the closest name to the root.

Path getName(int index)

6

Returns a path object that is part of this path object; the returned path object has a name that begins at beginIndex till the element at endIndex - 1. In other words, beginInedx is inclusive of the name in that index and exclusive of the name in endIndex. Throws IllegalArguementException if begin index is >= number of elements or endIndex number of elements.

Path subPath(int beginIndex, int endIndex)

7

Removes redundant elements in path such as . (dot symbol that indicates current directory) and ..(double dot symbol that indicates parent directory)

Path normalize()

8

Resolves a path against the given path.

Path resolve(Path or String other)

9

Returns true if the given path is an absolute path; false if not.

Boolean isAbsolute()

10

Returns true if this Path object starts with the given path, or false if not.

Path startsWith(String or Path path)

11

Returns the absolute path

Path toAbsolutePath()

12

Returns the URI from the path

URI toUri()

13

Returns an absolute path, but also normalizes it. Also resolves symbolic links. Unlike other methods, throws exception if target does not exist in filesystem.

toRealPath()

14

Checks equality of two path objects, returns true if equal, false if not.

equals()

15

Returns 0 if both paths are equal, a positive integer if this path is lexographically greater than the parameter path, and a negative integer if it is lexographically less.

compareTo()

16

Not actually part of the path interface, but the easiest way to get an actual path object.

Paths.get(String string)