Class CSVManager

java.lang.Object
collectionManagers.CSVManager
All Implemented Interfaces:
FileManager

public class CSVManager extends Object implements FileManager
The CSVManager class provides methods for working with files in .csv format. The class implements the Managers interface.
See Also:
  • Constructor Details

    • CSVManager

      public CSVManager()
  • Method Details

    • readFromFile

      public ArrayList<String> readFromFile(String pathToDataFile)
      Reads a CSV file at the specified path and returns an ArrayList containing each row of the file as a comma-separated string.
      Specified by:
      readFromFile in interface FileManager
      Parameters:
      pathToDataFile - The path to the CSV file to read.
      Returns:
      An ArrayList containing each row of the CSV file as a comma-separated string.
      Throws:
      IllegalArgumentException - If there was an error reading the CSV file, or if the file format was invalid.
    • write

      public void write(String pathToDataFile, String[] header, List<String> records) throws IOException
      Writes a collection of records to a CSV file at the specified path, using the given header and records array.
      Specified by:
      write in interface FileManager
      Parameters:
      pathToDataFile - The path to the CSV file to write to.
      header - An array of strings representing the header row of the CSV file.
      records - An array of objects representing the records to write to the CSV file. Each record should be an array of objects corresponding to a row in the CSV file.
      Throws:
      IOException - If there was an error writing to the CSV file.