aspose file tools*
The moose likes I/O and Streams and the fly likes strategy to read columns in File IO Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "strategy to read columns in File IO" Watch "strategy to read columns in File IO" New topic
Author

strategy to read columns in File IO

Nitesh Nirala
Greenhorn

Joined: Jan 06, 2013
Posts: 8
I have got a huge csv file. Some sample records are given below:

#station,t1,t2,t3,É,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Parliament,-,-,-,-,-,5:30,-,5:46,-,5:57,-,6:16,6:27
Melbourne Central,-,-,-,-,-,5:32,-,5:48,-,5:59,-,6:18
Flagstaff,-,-,-,-,-,5:33,-,5:49,-,6:00,-,6:19,6:30
Southern Cross,-,-,-,-,-,5:35,-,5:51,-,6:02,-,6:21,6:32

Detail records can be seen here webpage. (Each train schedule needs to be one object in this case)

I want to create each column as an object (not row) i.e t1,-,-,- (column 2) as one object and then t2,-,,(column 3) as another and so on.

What is the best way for accomplishing this? Will appreciate your response.

Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2317
    
  49
I don't understand why you want to store the information in columns when it's clearly related by row but the easiest way is to have an ArrayList object for each column and as you parse the file add each piece of data to the appropriate ArrayList. If you know the number of columns you could store the ArrayLists column objects in an array (otherwise you could store them in an ArrayList).
Nitesh Nirala
Greenhorn

Joined: Jan 06, 2013
Posts: 8
Thank you very much Tony.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2317
    
  49
My pleasure.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: strategy to read columns in File IO