-
Notifications
You must be signed in to change notification settings - Fork 1
CSVWriter Class
Natalie L edited this page Dec 5, 2024
·
1 revision
The CSVWriter class is part of the services package
(package org.example.globalgoodsindex.services). It provides methods to write data (such as salaries and products)
to CSV files. The class saves files in the /src/main/resources/data directory, which is determined dynamically
using
System.getProperty("user.dir") to get the current working directory.
Writes a list of Salary objects to a CSV file.
- Creates a directory and CSV file in the
data/salariesfolder. - Iterates through the provided list of
Salaryobjects and writes each entry to the file, with each line containing the country name and salary.
- Catches
IOExceptionif there is an issue with file writing, logging the error message to the console.
Writes a list of product data to a CSV file.
- Creates a directory and CSV file in the
data/productsfolder. - Writes the header row first, followed by data rows for each product.
- Catches
IOExceptionif there is an issue with file writing, logging the error message to the console.