• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Best way to read data from a csv file and compare and display

Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 3 csv files as follows -
author file columns - emailID | firstname | lastname
books file columns - title | isbn | author_email | description
magazine file Columns - title | isbn | author_email | releasedate

I need to display -
1) Based on the ISBN display all books and magazines
2) All books and magazines by an author
3) All books and magazines by title

I am using Buffered reader as of now -

I am confused about how to proceed with multiple files. Here are the approaches that i have considered -

1) change string csv csvFileToRead to a string array - String[] csvFileToRead = {"data/autoren.csv", "data/buecher.csv", "data/zeitschriften.csv"};
Pass each index each time to a method returning all rows but getting stuck with DS to use. I think ArrayList wont suffice since i need separated data. Should i use a 2D array? Do i need to read and store data in a DS in order to achieve the goal?
2) Should i make 3 different classes with getters and setters for authors, book and magazine?

What is the ideal way to do this? Please suggest.
Posts: 43016
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this was my problem I'd use one of the many available CSV libraries: see "Excel" in https://coderanch.com/how-to/java/AccessingFileFormats for a list. Most of those provide an object model to work with.
Dan Foster
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I completed the code and have 3 methods for the data i needed to display. Since the return type of all these methods is void, can anyone tell me how to test these methods using JUnit? Moreover I have 3 more methods which extract and return data to the specific and the return type is List<authors>. How can i test these methods?
I don't even know how to spell CIA. But this tiny ad does:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic