King
King

Reputation: 5

get csv data using java and validate it against expected results

I have the following data in a CSV file:

video1duration,video2duration,video3duration
00:01:00, 00:00:24, 00:00:15
00:01:00, 00:00:24, 00:00:15
00:01:00, 00:00:24, 00:00:15

The file is stored in a folder locally in my computer. I need help with writing code to do the followings: - pass the path of the CSV file to access its data, then treat the data as actual data and then validate each cell/value against expected data that will be written in the IDE as follows:

video1duration,video2duration,video3duration
00:02:00, 00:05:24, 00:00:15
00:04:00, 00:10:24, 00:00:15
00:01:00, 00:00:24, 00:00:15

Upvotes: 0

Views: 611

Answers (1)

Fa'Reed
Fa'Reed

Reputation: 11

As I understand your question, you have two-stage process. Trying to merge these two separate things into one will certainly result in less legible and harder-to-maintain code (everything as one giant package/class/function).

Your first stage is to import a .csv file and parse it using any of these 3 methods: Using java.util.Scanner Using String.split() function Using 3rd Party libraries like OpenCSV

It is possible to validate that your .csv is valid, and that it contains tabular data without knowing or caring about what the data will later be used for.

In the second stage take tabular data (e.g. an array of arrays) and turn it into a tree. At this point, your hierarchy package will be doing validation but it will only be validating the tree structure (e.g. every node except the root has one parent, etc.). If you want to delve further this might be interesting: https://www.npmjs.com/package/csv-file-validator.

Upvotes: 1

Related Questions