March 2018
Intermediate to advanced
208 pages
4h 52m
English
| | class Logbook { |
| | |
| | static final Path LOG_FOLDER = Paths.get("/var/log"); |
| | static final Path STATISTICS_CSV = LOG_FOLDER.resolve("stats.csv"); |
| | static final String FILE_FILTER = "*.log"; |
| | |
| | void createStatistics() throws IOException { |
| | DirectoryStream<Path> directoryStream = |
| | Files.newDirectoryStream(LOG_FOLDER, FILE_FILTER); |
| » | BufferedWriter writer = |
| | Files.newBufferedWriter(STATISTICS_CSV); |
| | |
| | try { |
| | for (Path logFile : directoryStream) { |
| | final String csvLine = String.format("%s,%d,%s", |
| | logFile, |
| | Files.size(logFile), |
| | Files.getLastModifiedTime(logFile)); |
| | writer.write(csvLine); |
| | writer.newLine(); |
| | } |
| | } finally { |
| » | directoryStream.close(); |
| | writer.close(); |
| |