Adam S
04/21/2024, 9:57 AMJaap Beetstra
04/21/2024, 10:23 AMJaap Beetstra
04/21/2024, 10:23 AMStefan Oltmann
04/21/2024, 11:43 AMChrimaeon
04/21/2024, 2:29 PM.nio.
stands for Non-Blocking ;-)
So both of the “file” API have their use case.Stefan Oltmann
04/21/2024, 2:32 PMSometimes NIO is claimed to mean Non-blocking IO. However, this is not what NIO meant originally. Also, parts of the NIO APIs are actually blocking - e.g. the file APIs - so the label "Non-blocking" would be slightly misleading.
Klitos Kyriacou
04/22/2024, 8:12 AMval file = File("some-file")
val deleted = file.delete()
if (!deleted) {
// How on Earth do you find out why it couldn't be deleted?
}
Versus:
val path = Path("some-file")
Files.delete(path) // throws exception with useful explanatory message
Also, Kotlin has some useful exceptions on java.nio.file.Path
Stefan Oltmann
04/22/2024, 8:14 AMAdam S
04/22/2024, 9:08 AMwhy do you consider java.nio.Path superior to java.util.File?More than anything, it's the inconsistency that bugs me. Sometimes I'll be using multiple libraries, and some use File, and others use Path, so I have to constantly convert between them.
Stefan Oltmann
04/22/2024, 9:10 AMAdam S
04/22/2024, 9:14 AMStefan Oltmann
04/22/2024, 9:15 AMStefan Oltmann
04/22/2024, 9:17 AMStefan Oltmann
04/22/2024, 9:19 AMKlitos Kyriacou
04/22/2024, 9:41 AMjava.io.File
. For another example, File.createTempFile
has a potential security vulnerability which is fixed in java.nio.file.Files
. I can't think of anything that File
can do that java.nio.file.Files
can't. So even if it's just for those two issues (there are probably more), applications might as well just stick to Files
for consistency. Note that other <http://java.io|java.io>
classes are still useful.Stefan Oltmann
04/22/2024, 5:28 PMByteReader
implementation that makes use of the performance. Right now it's just creating a InputStream and reads from that - I guess that's not the best performance, right?