Path and File Object Methods Flashcards

1
Q

How to create a Path object?

A

Path.get(“”);

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

Path method for returning a File object

A

Path.toFile();

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

Path method for returning URI object

A

Path.toURI();

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

Path.getPath() is a shorthand for the class?

A

java.nio.file.FileSystem.getPath()

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

Medhod of File object to get Path object

A

File.getPath()

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

Path method for getting the number of elements in path and a reference to each element.

A

Path.getNameCount()

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

Path method for getting the element name. Returns a Path object.

A

Path.getName()

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

Path method for checking if the Path object is absolute. Returns boolean.

A

Path.absolute()

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

Path method for converting the relative Path object to absolute. Returns Path object

A

Path.toAbsolute();

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

Path method for getting Path object representing the filename

A

Path.getFileName()

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

Path method for getting Path object representing the parent path.

A

Path.getParent()

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

Path method for getting the root path object.

A

Path.getPath();

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

Path method which returns relative path referenced by inclusive start index and exclusive end index

A

Path.subpath(, )

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

Path method for constructing a relative path from one Path object to another

A

Path.relativize();

Path path3 = Paths.get(“E:\habitat”);
Path path4 = Paths.get(“E:\sanctuary\raven”);
System.out.println(path3.relativize(path4));
System.out.println(path4.relativize(path3));

..\sanctuary\raven
....\habitat

Both has to be relative. or both has to be absolute.

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

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

A

Path.resolve()

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

There are times that the resulting Path of relativize method contains redundant path. This path method cleans up the path

A

Path.normalize()

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

Path object may point to non-existent file. This method talkes a path object and returns a real Path.
object.

Converts relative path to absolute Path.
Calls normalize implicitly.

A

Path.toRealPath();

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

Files method for checkin if the Path object exists.

A

File.exists();

19
Q

Files method for checking if two Path objects are the same.

A

File.isSameFile();

20
Q

Files method for creating directory. Throws exception if the directory already exists.

A

Files.createDirectory();

21
Q

Files method for creating directories. Does not throw exception if the File does not exist.

A

Files.createDirectories();

22
Q

Files method for copying files and directories . Throws IO Exception.

A

Files.copy(source Path, destination Path)

23
Q

Files contain two overloaded methods for coyping files

A

Files.copy(InputStream, Path);

Files.copy(Path, OutputStream)

24
Q

Files method for renaming file or directory

A

Files.move(sourcePath, destinationPath)

25
Q

Files method for deleting file.

A

Files.delete(Path);

26
Q

Files method for deleting files and checks if it exists

A

Files.deleteIfExists();

27
Q

Files method for reading the file contents.

Returns BufferedReader object

A

Files.newBufferedReader(Path, Charset);

28
Q

Files method for writing file

Return BufferedWriter object

A

Files.newBufferedWriter(Path, Charset);

29
Q

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

A

List lines = Files.readAllLines()

30
Q

Files method for checking if the Path is regular file.

A

Files.isRegularFile(Path)

31
Q

Files method for checking if the Path is a directory.

A

Files.isDirectory(Path)

32
Q

Files method for checking if it is a symbolic link

A

Files.isSymbolicLink(Path)

33
Q

FIles Method for checking if the file is Hidden

A

Files.isHidden()

34
Q

Files method for checking if the file is readable

A

Files.isReadable()

35
Q

Files method for checking if the file is executable.

A

Files.isExecutable(Path)

36
Q

Files method for checking the size

A

Files.size()

37
Q

Files method to get the last modified time.

A

FileTime ft = Files.getLastModifiedTime()

38
Q

Files method for setting the last modified time.

A

Files.setLastModifiedTime(FileTime ft)

39
Q

Files method for setting and getting the owner

A

getOwner() and setOwner(Path, UserPrincipal)
UserPrincipal owner = FileSystems.getDefault().getUserPrincipalLookupService()
.lookupPrincipalByName(“jane”);

Path path = …
UserPrincipal owner = path.getFileSystem().getUserPrincipalLookupService()
.lookupPrincipalByName(“jane”);

40
Q

Files method for getting the read only attributes of the files.

A

BasicFileAttributes bfa = Files.readAttributes(Path,Class<a>) </a>

41
Q

Files method for getting the view of attributes and allows changing of attributes.

A

BasicFileAttributeView bfav = Files.getFileAttributeView()

42
Q

Files method returns a Stream object that traverses the directory in a depth-first, lazy manner.

A

Stream sp = Files.walk(path)

43
Q

Files method for listing the contents of directory

A

Files.list()

44
Q

Files method that returns a Stream object to read content and does not suffer from this same issue. The contents of the file are read and processed lazily, which means that only a small portion of the file is stored in memory at any given time.

A

Stream lines = Files.lines(Path)