Search This Site
Jul 29 2010 16:51 UTC | ||||||||||
Tutorials
CSV ManagerRatingsQuality
Recommendations
Questions
Got a question for us? Bookmarks |
List Collections Data
CSV Manager can load and save your data as a pure Java collection: a 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 Use this method when...
loadAsLists
method can take a String containing the file path, or a File object.
How exactly is the data stored?
The What happens when some rows contain more fields than others?
The 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 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
What about saving data to a CSV file?
You can also save data to a CSV file using a
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 SupportAll CSV Manager licenses include a FREE 6 month Email Support Package, worth $1500.00. FREE XML ManagerAll CSV Manager licenses include a FREE XML Manager single developer license, worth $170.00. Any CSV FormatThe CSV Manager component can handle any style of tabular text data, from Excel CSV files to the UNIX passwd file.
| ||||||||
|
comment on this page
Home |
Search |
About Us |
Contact Us |
Our Products |
Documentation |
Resources |
Login
Copyright © 2004-2010 Ricebridge. All Rights Reserved. | ||||||||||