-3

For my Finals Project in my Introduction to Programming class, I need to read through a csv file, instructor provided, and divide up the information into specific arrays so that eventually I can sort through them.

An example from the CSV file that I need to split up is:

1013,Demizz,Tucson,Arizona,85710
I0053,1/11/2014,7298.88
P534,485.67,Nulla ac enim. In tempor turpis nec euismod scelerisque quam turpis adipiscing lorem vitae mattis nibh ligula nec sem. Duis aliquam convallis nunc.
P296,300.92,Cras non velit nec nisi vulputate nonummy. Maecenas tincidunt lacus at velit. Vivamus vel nulla eget eros elementum pellentesque. Quisque porta volutpat erat.

-1

Company ID,Name,City,State,Zip

Invoice#,Date,Amount

Payment #,Amount,Description

Invoice#,Date,Amount

Company ID,Name,City,State,Zip

Invoice#,Date,Amount

-1

is the format of the file. (The description is in a random language he provided) I just need to know how for example I could read up the 1013 then hit the comma and load that into an array I labeled as companyID, then go and read up into the next comma and make that the company name, and the rest of that line needs to be stored into another array but is useless information in sorting the information. The -1 at the end terminates the file.

For the project I can only use arrays/arraylists, if/else, loops, try/catch. Just the basics of java.

Jonathan.Brink
  • 19,445
  • 13
  • 59
  • 98

1 Answers1

0

Just use firstLine.split(","), where firstLine is a string with commas, and it will return a String[] with the seperated values.

ben720
  • 76
  • 3