January 2018
Intermediate to advanced
434 pages
14h 1m
English
Did you note that we used the use() and useLines() methods for reading the file? The call to the Closeable.use() function will automatically close the input at the end of the lambda's execution. Now, we can of course use Reader.readText(), but that does not close the stream after execution. There are other methods apart from use(), such as Reader.readText() and so on, that can be used to read the contents of a stream or file. The decision to use any method is based on whether we want the stream to be closed on its own after execution, or we want to handle closing the resources, and whether or not we want to read from a stream or directly from the file.
Read now
Unlock full access