Skip to content

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.

Methods

writeSalariesToCSV

Purpose:

Writes a list of Salary objects to a CSV file.

Description:

  • Creates a directory and CSV file in the data/salaries folder.
  • Iterates through the provided list of Salary objects and writes each entry to the file, with each line containing the country name and salary.

Error Handling:

  • Catches IOException if there is an issue with file writing, logging the error message to the console.

writeProductsToCSV

Purpose:

Writes a list of product data to a CSV file.

Description:

  • Creates a directory and CSV file in the data/products folder.
  • Writes the header row first, followed by data rows for each product.

Error Handling:

  • Catches IOException if there is an issue with file writing, logging the error message to the console.

Clone this wiki locally