Ricebridge
Search This Site
Jul 29 2010 16:51 UTC


$15 Gift Certificate for every bug you find.

MaxMind GeoIP
This IP address to country database is provided as a CSV file that can easily be read by CSV Manager.

Got a question for us?
Just Ask!

Bookmark List collections feature description for Ricebridge Java CSV Manager Component at del.icio.us Digg List collections feature description for Ricebridge Java CSV Manager Component at Digg.com Bookmark List collections feature description for Ricebridge Java CSV Manager Component at reddit.com Bookmark List collections feature description for Ricebridge Java CSV Manager Component at YahooMyWeb Bookmark List collections feature description for Ricebridge Java CSV Manager Component at Spurl.net Bookmark List collections feature description for Ricebridge Java CSV Manager Component at Simpy.com Bookmark Polyphasic Mutants at NewsVine Blink this List collections feature description for Ricebridge Java CSV Manager Component at blinklist.com Bookmark List collections feature description for Ricebridge Java CSV Manager Component at Furl.net Fark List collections feature description for Ricebridge Java CSV Manager Component at Fark.com

List Collections Data

CSV Manager can load and save your data as a pure Java collection: a List of Lists.

Code Example

File       csvFile    = new File("mydata.csv");
CsvManager csvManager = new CsvManager();
List       data       = csvManager.load( csvFile );

for( int line = 0; line < data.size(); line++ ) {
  System.out.println( "line: "+line );

  List fields = (List) data.get(line);
  for( int field = 0; field < fields.size(); field++ ) {
    System.out.println( "field "+field+" has value: " 
                        + fields.get(field) );
  }
}

This code example loads the data in a CSV file into a List of Lists collection, which can then be used as a Java collection.

Use this method when...

  • you just want to read all the data into memory quickly.
  • your data may not be completely regular.
  • you need to manipulate the data using the Java Collections API
The loadAsLists method can take a String containing the file path, or a File object.

How exactly is the data stored?

The List object returned by the loadAsLists method contains all the rows of the CSV file as elements. Each element is also a List, containing String objects for each data field in the row.

What happens when some rows contain more fields than others?

The List object representing each row of the CSV file contains as many elements as needed to store all the data fields in the row, even when there are more data fields than expected.

What happens when some rows are missing fields?

CSV Manager keeps track of the default number of data fields that you expect in your CSV file (you can set the default number of fields, or let CSV Manager automatically use the number of fields in the first row), and makes sure that the Lists representing each row always contain at least the default number of elements, even if they are empty Strings.

OK, how do I get the column headers?

Assuming the headers are in the first line of the CSV file, you have them directly in the first row. You don't need to do anything special. If they are not in the first line, then they are either in a predefined line (say line 3), or you can set CSV Manager to ignore empty lines, until you find them.

But my data isn't in a file!

You are not restricted to loading CSV data only from files. You can also load data from Strings (loadAsListsFromString(String) method) and from InputStreams (loadAsLists(InputStream) method). This means that you can use CSV Manager in a completely dynamic way within your application.

What about saving data to a CSV file?

You can also save data to a CSV file using a List of Lists of Strings. Just create a List, and add some new Lists containing Strings to it. The Lists can be different sizes and can contain empty Strings. Here's the example code:

List data = new ArrayList();

List row = new ArrayList();
row.add("Color"); row.add("Code");
data.add(row);

row = new ArrayList();
row.add("red"); row.add("ff0000");
data.add(row);

row = new ArrayList();
row.add("green"); row.add("00ff00");
data.add(row);

row = new ArrayList();
row.add("blue"); row.add("0000ff");
data.add(row);

CsvManager csvManager = new CsvManager();
File csvFile = new File("mydata.csv");
csvManager.saveAsLists( csvFile, data );

Of course, you will probably create the lists dynamically rather than hard-coding them.

What other data structures can you handle?

We also support:

I need to see something working.

Sure, no problem. Head on over to our online demo and try out CSV Manager on your own data.

I have another question...

If you have a particular question you need answered, just ask! We're happy to explain exactly how CSV Manager works and show you how to use it.

FREE Email Support

All CSV Manager licenses include a FREE 6 month Email Support Package, worth $1500.00.

Email Support Package

FREE XML Manager

All CSV Manager licenses include a FREE XML Manager single developer license, worth $170.00.

Convert CSV to XML

Any CSV Format

The CSV Manager component can handle any style of tabular text data, from Excel CSV files to the UNIX passwd file.

CSV Formats

"Your product actually did help a lot! I was able to accelerate my development time quite a bit and your service support was also real nice."
Luis Garcia,
Independent Contractor
"An event-based CSV parser is so much more flexible and elegant than the free alternatives that I found. We use it for applications which require a mixture of XML and CSV data. This requires a parser that performs well, uses memory efficiently, simplifies data access and accurately formats output data. We found the Ricebridge parser easy to work with, conspicuously well documented and capable of handling large (500kb+) files. That's a big thumbs up from all the Gaisan team."
Shane Dempsey,
Gaisan
"I would have spent all day trying to read CSV fields that contained commas. I bought your software about 15 minutes ago and my problem is ALREADY solved. Thank you very, very much for a quality piece of software."
Adrian Klingel,
Illumaware
"Ricebridge CSV Manager was really easy to integrate into our existing system, and has been completely reliable for data transfer, not to mention a big time saver!"
Fred Crowe, Speech-Writers
comment on this page Home | Search | About Us | Contact Us | Our Products | Documentation | Resources | Login
Copyright © 2004-2010 Ricebridge. All Rights Reserved.