diff options
author | Jonas Smedegaard <dr@jones.dk> | 2025-04-19 21:54:14 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2025-04-19 21:54:14 +0200 |
commit | 887b75a76896d373015926857e3335c93df9d7b8 (patch) | |
tree | 78765afd9922bf7f123fb17f0668a448db60855c /dk/abcdefghijklmnopqrstuvxyzæøå | |
parent | dce39dc474326fa29d7e5add9b0bc64613603f56 (diff) |
add class ReadCombi
Diffstat (limited to 'dk/abcdefghijklmnopqrstuvxyzæøå')
-rw-r--r-- | dk/abcdefghijklmnopqrstuvxyzæøå/bachelorizer/ReadCombi.java | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/dk/abcdefghijklmnopqrstuvxyzæøå/bachelorizer/ReadCombi.java b/dk/abcdefghijklmnopqrstuvxyzæøå/bachelorizer/ReadCombi.java new file mode 100644 index 0000000..a3ddd4e --- /dev/null +++ b/dk/abcdefghijklmnopqrstuvxyzæøå/bachelorizer/ReadCombi.java @@ -0,0 +1,56 @@ +// SPDX-FileCopyrightText: 2025 Jonas Smedegaard <dr@jones.dk> +// SPDX-License-Identifier: GPL-3.0-or-later + +package dk.abcdefghijklmnopqrstuvxyzæøå.bachelorizer; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.io.IOException; +import java.util.List; + +/// ReadCombi - read and parse data file +/// +/// File reader class slurping and parsing a comma-separated file. +/// +/// @version 0.0.1 +/// @see <https://moodle.ruc.dk/mod/assign/view.php?id=523186> +public class ReadCombi { + + /// Default constructor + /// + /// @param args command-line arguments or default demo data + public ReadCombi(final Path path) { + + try { + // slurp all content at once + List<String> lines = Files.readAllLines(path); + + for (String line : lines) { + String[] values = line.split(","); + + for (String value : values) { + System.out.print(value + "\t"); + } + System.out.println(); + } + + } catch (IOException e) { + e.printStackTrace(); + } + } + + /// JVM entry point + /// + /// @param args command-line arguments + public static void main(final String[] args) { + + // first argument, if provided, is the data file path; + // else use upstream named file in current directory. + Path path = (args.length > 0) + ? Paths.get(args[0]) + : Paths.get("combi.txt"); + + new ReadCombi(path); + } +} |