Solution to this repo.
- Download, import and run the code of this repository.
- Open the TODO tab and implement the code required to transform each line in the file into a Product object.
- Create a class called ProductsService and move your code there to store the list of products loaded from the CSV.
- Override the toString method of the Product class and run your code to print your products and verify it works as expected.
- Create an interface to define how other users could use your library.
- Change your code on the main method to use the interface and preview how your library works.
- Read the following article to understand how to add Maven to the Java project
- Once your project has the Maven include import the following library into your dependencies:
- Read the Open CSV documentation to understand how to use the CSV library:
- Modify your code to use the Open CSV library instead of reading and processing line by line.
- The Maven archetypes are outdated when you create new projects in VS Code. Nothing has really changed in years.
- I always use double, so I was surprised to see a float used in the starter code.
- Double can be overkill, and maybe I should use float more often.
ScannerandFileReaderare slower thanBufferedReader.- I looked into various CSV libraries. Deephaven CSV seems like an interesting new library. Super CSV seems to be slightly outdated.
- I thought about using different branches or different classes, but I decided just to comment out different approaches for right now.
- When you uncomment any section, you will need to add the imports.
- You need to add an empty constructor to any POJO class for opencsv to parse your CSV file. Otherwise, you will get a CSV bean introspection exception.
- Different classes or branches for the different approaches
- Scaler - float vs double
- YouTube - Reading and parsing delimited CSV data from a file into an Object in Java
- Stack Overflow - fastest way to read a csv file in java
- How to do in Java - parse csv files in java
- YouTube - Reading a CSV in Java
- YouTube - How to read and process CSV file in Java? (with Streams)
- mkyong - how to read and parse csv file in java
- Geeks for Geeks - iterate map java
- Github - csv error handling strategies
- North Concepts - continue after an error
- Stack Overflow - how to ignore exceptions in java
- Source Forge - open csv quick start
- Baeldung - opencsv
- YouTube - Read CSV with Bean Class Java | CSV Bean Builder in Open CSV| CsvBindByName Open CSV |Opencsv Java
- Stack Overflow - csv bean introspection exception