java 2 3
fdsa
fdsa
Set of flashcards Details
Flashcards | 496 |
---|---|
Language | Deutsch |
Category | Computer Science |
Level | Other |
Created / Updated | 06.12.2020 / 24.01.2021 |
Weblink |
https://card2brain.ch/box/20201206_java_2_3
|
Embed |
<iframe src="https://card2brain.ch/box/20201206_java_2_3/embed" width="780" height="150" scrolling="no" frameborder="0"></iframe>
|
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
What happens here? Symbolic link from /zebra to /horse and current working direectory is /horse/schedule
System.out.println(Paths.get("/zebra/food.txt").toRealPath());
System.out.println(Paths.get(".././food.txt").toRealPath());
Both times the output is: /horse/food.txt
Does files have methods like mkdir/renameTo?
No but move() and createDirectory()
Whats the signature of Files.exists?
public static boolean exists(Path path, LinkOption... options)
Does Files.isSameFile follow symbolicLinks?
Yes
Can Files.isSameFile also check directories?
yes
What happens in isSameFile when a Path not exists? Are there exceptions to this?
Will trigger an exception, specialcase: If two path objects are equal in terms of equals() then it wont check if the file exists
Does Files.isSameFile compare the contents?
No
How to create a Directory with Files-class? (Methods)
- public static Path createDirectory(Path dir, FileAttribute<?>... attrs) throws IOException
- public static Path createDirectories(Path dir, FileAttribute<?>... attrs) throws IOException