aboutsummaryrefslogtreecommitdiff
path: root/dk/abcdefghijklmnopqrstuvxyzæøå/bachelorizer/ReadCombi.java
blob: a3ddd4e43b5a9af9526beedb38d791a2e7de7ed3 (plain)
  1. // SPDX-FileCopyrightText: 2025 Jonas Smedegaard <dr@jones.dk>
  2. // SPDX-License-Identifier: GPL-3.0-or-later
  3. package dk.abcdefghijklmnopqrstuvxyzæøå.bachelorizer;
  4. import java.nio.file.Files;
  5. import java.nio.file.Path;
  6. import java.nio.file.Paths;
  7. import java.io.IOException;
  8. import java.util.List;
  9. /// ReadCombi - read and parse data file
  10. ///
  11. /// File reader class slurping and parsing a comma-separated file.
  12. ///
  13. /// @version 0.0.1
  14. /// @see <https://moodle.ruc.dk/mod/assign/view.php?id=523186>
  15. public class ReadCombi {
  16. /// Default constructor
  17. ///
  18. /// @param args command-line arguments or default demo data
  19. public ReadCombi(final Path path) {
  20. try {
  21. // slurp all content at once
  22. List<String> lines = Files.readAllLines(path);
  23. for (String line : lines) {
  24. String[] values = line.split(",");
  25. for (String value : values) {
  26. System.out.print(value + "\t");
  27. }
  28. System.out.println();
  29. }
  30. } catch (IOException e) {
  31. e.printStackTrace();
  32. }
  33. }
  34. /// JVM entry point
  35. ///
  36. /// @param args command-line arguments
  37. public static void main(final String[] args) {
  38. // first argument, if provided, is the data file path;
  39. // else use upstream named file in current directory.
  40. Path path = (args.length > 0)
  41. ? Paths.get(args[0])
  42. : Paths.get("combi.txt");
  43. new ReadCombi(path);
  44. }
  45. }