Writing a CSV file, reading a CSV file and writing data from CSV to txt file in Java using OpenCSV. Additionally, the program counts the sum and average data.
- This method is responsible for writing some example data to a CSV file.
- First we create an instance of CSVWriter by passing FileWriter object as a parameter and example file name as s parameter.
- Adding examples values and saving to salaries.scv file.
- Default Separated Value is a comma → CSVWriter.DEFAULT_SEPARATOR
- This method is responsible for reading data from the salaries.csv file.
- After reading the data the count method is called by passing data as a parameter.
- This method is responsible for counting a sum and an average values from the salaries.csv file.
- First we count a sum and an average row by row.
- After counting, the displayResults is called by passing two parameters.
- This method is responsible for displaying data in console in specific format.
- After processing the data, the writingTXTFile method is called by passing rows as a parameter.
- This method is responsible for writing data from salaries.csv to salariesStatistics.txt.
- First we create an instance of FileWriter by passing file name as a parameter.
- Saving data to to salariesStatistics.txt
- Install IntelliJ IDEA
- Install JDK (Java Development Kit)
- OpenCSV → is a CSV parser library for Java. Dependency responsible for this library was added to pom.xml file.
- Download and install IntelliJ IDEA (community version is free)
- Download and install JDK
- Set the JDK path on Windows
Follow this link to see the instruction about installing necessery tools on Linux
- Download the zip or clone the Git repository
- Unzip the zip file to you projects directory
- Open IntelliJ
- File → Open → Navigate to the folder where you unzipped the zip
- Select the right project
- If you want to clone the repository you need to:
- Copy the project link
- Open IntelliJ
- File → New → Project from Version Control
- Paste the link and click Clone
- Right Click on the file and Run as Java Application
Probably after openning the project you will have to set the JDK in IntelliJ IDEA.
- Project structure → Project settings → Project → SDK → choose the right JDK version (1.8 or newer)
- IntelliJ IDEA → https://www.jetbrains.com/idea/download/#section=windows
- JDK → https://www.oracle.com/java/technologies/downloads/ or https://adoptopenjdk.net/?variant=openjdk11&jvmVariant=hotspot
- Export an IntelliJ IDEA project to Eclipse → https://www.jetbrains.com/help/idea/exporting-an-intellij-idea-project-to-eclipse.html
- How to set JDK path on Windows → https://www.poftut.com/how-to-set-java-jre-and-jdk-home-path-and-environment-variables-on-windows/