September 2019
Intermediate to advanced
816 pages
18h 47m
English
The Files class comes with two methods that can read an entire text file in memory. One of them is List<String> readAllLines(Path path, Charset cs):
List<String> lines = Files.readAllLines( chineseFile, StandardCharsets.UTF_16);
Moreover, we can read the entire content in a String via Files.readString(Path path, Charset cs):
String content = Files.readString(chineseFile, StandardCharsets.UTF_16);
While these methods are very convenient for relatively small files, they are not a good choice for large files. Trying to fetch large files in memory is prone to OutOfMemoryError and, obviously, will consume a lot of memory. Alternatively, in the case of huge files (for example, 200 GB), we can focus on memory-mapped ...