File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Groovy and the fly likes CSV File creation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Languages » Groovy
Bookmark "CSV File creation" Watch "CSV File creation" New topic

CSV File creation

Bill Dowd

Joined: Aug 17, 2012
Posts: 4
Hi all,

I'm a relative newcomer to Groovy/Java and have a question about efficiently outputting data to a .csv file. Basically, as my simulation model runs, I save key information in a list. For example, I track tasks undertaken by agents, so I save ID, duration, and action. I end up with a long list that is divisible by 3, but has a number of elements in it. I use the following code to output it into a 3 column csv file:

Essentially, I take the first three elements of my list, create a list that represents a row, add it to a list of maps, and then write to the csv file one row at a time. It produces perfect output, but it takes forever (these lists have thousands of elements in them). It's much faster to just write the original list to CSV, but then I end up with one row rather than a three-column table. I can always process the data in something that I'm more familiar with, like Stata, but I figured I'd ask about more efficient ways to do this. Thanks in advance for your thoughts!

Bill Dowd

Joined: Aug 17, 2012
Posts: 4
I figured out a way around it. Thanks, all!
wood burning stoves
subject: CSV File creation
Similar Threads
What is the best way to store List<List<String>> in database?
save my application
Generate CSV from Resultset
data on specific place in text file with xml or without
Can we use jsp stuff in onklick events