I want to be able to read data from a csv file (comma seperated,tab seperated or space seperated) and pass the data into an array.my intentions are to combine four classes. such as a class for the data model,file reader, driver and textui. i can handle the textui and the driver but am finding it dificult with the other two classes as i am a beginner. Anyone care to help with some sample codes

Recommended Answers

All 6 Replies

You need to look at how to do two things:
1) Read lines from the file. An easy way to do this is using the Scanner class.
2) Split the lines at the comma: See the String class's split() method

thank you very much, that really helped. i want to further pass the data read from the csv file into a table. How do i go about it please?

Let's assume that you are going to put the file reading code into a method, eg readDataFrom(File f). In that method all you need to to do is to read the file, split the lines (as Norm said) and add that data to a 2D array. Finally you return the array. Then, when you need the data somewhere else you just call that method.

Thank you very much guys for all your contributions. my program is up and running. However i need to pass some information into the program to do some certain things.The program reads a csv file with data in rows and columns(source Data). it also reads a csv file with rows and columns(target data) on the same GUI but different panels. i want to pass mapping rules as an input to populate the target data and do some restructuring to support the target data.Please what kind of free grammar language do i use to write and how do i arrange these instructuctions that the system will understand and implement.

How do create an XSLT template to create transformation rules in rearranging a source data to conform to a target data.

What java classes are you wanting to use now?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.