fdsa


J. F.
Diese Karteikarten bieten einen umfassenden Überblick über die Java-Programmierung, insbesondere zu Themen wie Dateiverarbeitung, Funktionen und Sammlungen. Sie decken wichtige Konzepte wie das Arbeiten mit Pfaden, Dateien und Strings ab, sowie das Verhalten von Sammlungen und deren Sortiermethoden. Die Karteikarten sind ideal für Entwickler, die ihr Wissen in Java vertiefen möchten, insbesondere in Bezug auf die Handhabung von Sammlungen, das Sortieren und Vergleichen von Objekten sowie die Verwendung von Stream-APIs und Collectors.
Karten
496
Lernende
3
Sprache
Deutsch
Kategorie
Informatik
Stufe
Andere
Erstellt / Aktualisiert
06.12.2020 / 24.01.2021

Lernkarten

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

What happens with createDirectories if the directories already exists?

Will simply doe nothing -> createDirectory would throw an excetion

What happens with createDirectory if it already exists? What if the path leading up tp the directory does not exists?

throw an exception

What is the signature of Files.copy?

public static Path copy(Path source, Path target, CopyOption... options) throws IOException

Whats the default behavoiur of copy if the target already exists? 

Throws an exception

What happens here if food.txt and /enclosure exists?
var file = Paths.get("food.txt");
var directory = Paths.get("/enclosure");
Files.copy(file, directory);

Throws an exception -> enclosure already exists -> Path would have to be "/enclosure/food.txt"

What happens with Files.delete if a directory is not empty?

Throws an exception

What happens if delete/deleteIf is called on a symbolic link?

The link will be deleted, not the target

What does newBufferedReader() do?

Reads the file specified at the Path location

Lernen