r/javaTIL • u/TheOverCaste • Nov 16 '14
JTIL: File has a constructor which takes another file as its containing folder.
For example:
File parent = new File("folder");
File child = new File(parent, "file.txt");
File equivalent = new File("folder" + File.separator + "file.txt");
assert (child.getAbsolutePath().equals(equivalent.getAbsolutePath()));
3
Upvotes
6
u/aenigmaclamo Nov 16 '14
You should generally be using the newer Files and Paths API which have similar constructs.
https://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html
https://docs.oracle.com/javase/7/docs/api/java/nio/file/Path.html
https://docs.oracle.com/javase/7/docs/api/java/nio/file/Paths.html