java 2 3
fdsa
fdsa
-
- 1 / 496
-
Lernkarten
Do we make a difference in how we treat a instance if it is a file or directory in NIO2?
No
Does Path support symbolic links?
Yes
Does java.io.File support symbolic Links?
No
Can we create an instance of Path directly?
No, is a interface
Whats the syntax of the Path factory method?
public static Path of(String first, String... more)
Whats the characteristics of a relative / absolute path for the exam?
A absolute starts with / -> the root directory or with c: .. / d://
a relative would be f.e.: bird/parrot.png
What does the varags in Path.of do?
accepts additional path elements whcih will be combined and automatically be separated by the operation system-depending file separator
What are two ways to get a instance of Path?
Path.of and Paths.get
What are ways to get a Path instance from a Uri?
f.e.: URI a = new URI("file://iceman.txt");
Path b = Path.of(a);
Path c = Paths.get(a);
URI d = b.toUri();
How to get a Path via Filesystems? Whats the syntax?=
FileSystems.getDefault().getPath("/home/zooDirectory");
How to convert a Fileto a Path? How the other way around?
File file = new File("some.png");
Path path = file.toPath();
File backToFile = path.toFile();
Whats the enum value,type and inherited interface for not following symoblic links?
NOFOLLOW_LINKS , LinkOption, CopyOption/OpenOption
Whats the enum value,type and inherited interface for moving a file as atomic file system operation?
ATOMIC_MOVE, StandardCopyOption , CopyOption
Whats the enum value,type and inherited interface for coping existing attributes to new file?
COPY_ATTRIBUTES , StandardCopyOption , CopyOption
Whats the enum value,type and inherited interface for overwriting files if it already exist?
REPLACE_EXISTING , StandardCopyOption , CopyOption
Whats the enum value,type and inherited interface for appending to the end of a file if it is already open for write
APPEND, StandardOpenOption , OpenOption
Whats the enum value,type and inherited interface for creating a new file if it does not exist?
CREATE, StandardOpenOption, OpenOption
Whats the enum value,type and inherited interface for creating a new file if it does not exist or overwrite
CREATE_NEW, StandardOpenOption, OpenOption
Whats the enum value,type and inherited interface for opening for read access?
READ, StandardOpenOption, OpenOption
Whats the enum value,type and inherited interface for erase file and append to beginning if it is already open for write
TRUNCATE_EXISTING, StandardOpenOption, OpenOption
Whats the enum value,type and inherited interface for opening for write access?
WRITE, StandardOpenOption, OpenOption
Whats the enum value,type and inherited interface for following symbolic links?
FOLLOW_LINKS, FileVisitOption
Whats the default behaviour of Files.exists() for symbolicLinks?
checks the target of the smybolic link
Are Path instance mutable?
No, just like string-values
What happens here?
Path p = Path.of("whale");
p.resolve("krill");
System.out.print(p);
prints whale
Whats a rule of thumb when a method declares a IOException within NIO2?
When it requires the paths it operates on to exists
What happens if we call Path.getName with an invalid Index?
Throws an IllegalArgumentException at runtime
Are the references in Path.subpath(int beginIndex, int endIndex) inclusve or exclusive?
inclusive beginindex, exclusive endIndex
What happens with subpath if a invalid index is provided (also with getName(), subpath())
Throws a IllegalArgumentException
When does getParent() return null?
if operated on the root path or at the top of a relative path
What does getRoot return if the Path is a relative path?
Does not traverse outside the current working directory, returns null if it as the top of the relative path
Does getParent resolve pathSymbols like ".."?
No
Which Signatures of resolve exists?
- public Path resolve(Path other)
- public Path resolve(String other)
How does relativize work with relative Paths, how with absolute?
If both relative: computes like they are in the samye working directory
alternatively if both absoulte: computes the relative path from one to another, regardless of current working directory
if mixed a exception gets thrown
What happens with relativize if two absolute Paths doesnt have the same rootDir?
throw exception
What happens here?
var p3 = Path.of("../../fish.txt");
System.out.println(p3.normalize());
../../fish.txt
What happens here?
var p1 = Paths.get("/pony/../weather.txt");
var p2 = Paths.get("/weather.txt");
System.out.println(p1.equals(p2));
System.out.println(p1.normalize().equals(p2.normalize()));
false, true
What does toRealPath() do, whats the syntax?
public Path toRealPath(LinkOption... options) throws IOException
Eliminates any redundant path symbols, join the path with the curent working directory if the path is relative
Does toRealPath check if the file exists?
no, throws ioException
Does toRealPath follow symbolicLinks?
Yes