Package collectionManagers
Class CSVManager
java.lang.Object
collectionManagers.CSVManager
- All Implemented Interfaces:
FileManager
The CSVManager class provides methods for working with files in .csv format.
The class implements the Managers interface.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionreadFromFile
(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.void
Writes a collection of records to a CSV file at the specified path, using the given header and records array.
-
Constructor Details
-
CSVManager
public CSVManager()
-
-
Method Details
-
readFromFile
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 interfaceFileManager
- 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
Writes a collection of records to a CSV file at the specified path, using the given header and records array.- Specified by:
write
in interfaceFileManager
- 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.
-