September 2019
Intermediate to advanced
816 pages
18h 47m
English
Let's suppose that we have 10 numbers (integers and doubles) and we want them to be nicely formatted (have an indentation, alignment, and a number of decimals that sustain readability and usefulness) in a file.
In our first attempt, we wrote them to the file like so (no formatting was applied):
Path path = Paths.get("noformatter.txt");try (BufferedWriter bw = Files.newBufferedWriter(path, StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.WRITE)) { for (int i = 0; i < 10; i++) { bw.write("| " + intValues[i] + " | " + doubleValues[i] + " | "); bw.newLine(); }}
The output of the preceding code is similar to what's shown on the left-hand side of the following diagram:
However, ...