Path and File Object Methods Flashcards

(44 cards)

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
Files method for deleting file.
Files.delete(Path);
26
Files method for deleting files and checks if it exists
Files.deleteIfExists();
27
Files method for reading the file contents. | Returns BufferedReader object
Files.newBufferedReader(Path, Charset);
28
Files method for writing file | Return BufferedWriter object
Files.newBufferedWriter(Path, Charset);
29
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
List lines = Files.readAllLines()
30
Files method for checking if the Path is regular file.
Files.isRegularFile(Path)
31
Files method for checking if the Path is a directory.
Files.isDirectory(Path)
32
Files method for checking if it is a symbolic link
Files.isSymbolicLink(Path)
33
FIles Method for checking if the file is Hidden
Files.isHidden()
34
Files method for checking if the file is readable
Files.isReadable()
35
Files method for checking if the file is executable.
Files.isExecutable(Path)
36
Files method for checking the size
Files.size()
37
Files method to get the last modified time.
FileTime ft = Files.getLastModifiedTime()
38
Files method for setting the last modified time.
Files.setLastModifiedTime(FileTime ft)
39
Files method for setting and getting the owner
getOwner() and setOwner(Path, UserPrincipal) UserPrincipal owner = FileSystems.getDefault().getUserPrincipalLookupService() .lookupPrincipalByName("jane"); Path path = ... UserPrincipal owner = path.getFileSystem().getUserPrincipalLookupService() .lookupPrincipalByName("jane");
40
Files method for getting the read only attributes of the files.
BasicFileAttributes bfa = Files.readAttributes(Path,Class)
41
Files method for getting the view of attributes and allows changing of attributes.
BasicFileAttributeView bfav = Files.getFileAttributeView()
42
Files method returns a Stream object that traverses the directory in a depth-first, lazy manner.
Stream sp = Files.walk(path)
43
Files method for listing the contents of directory
Files.list()
44
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.
Stream lines = Files.lines(Path)