Search This Site
May 09 2008 22:48 UTC | ||||||||||
Tutorials
CSV ManagerRatingsQuality
Recommendations
Questions
Got a question for us? Bookmarks |
Event-driven DataCSV Manager can load and save your data using line-by-line events. This allows you to handle very large CSV files. Code Example
public class MyLineListener extends CustomLineListener {
public BadLine addLineImpl( String[] pLine, int pNumFields, long pLineNumber, String pOriginalLine ) {
System.out.print( "LINE:"+pLineNumber+": " );
for( int field = 0; field < pNumFields; field++ ) {
System.out.print( "FIELD "+field+":"+pLine[field] + (field < pNumFields-1?", ":"\n") );
}
return null;
}
}
public void loadCsv( File pCsvFile ) {
File csvfile = new File( "mydata.csv" );
CsvManager csvman = new CsvManager();
MyLineListener myln = new MyLineListener();
csvman.load( csvfile, myln );
}
This code example can load data from a very large CSV file one line at a time.
This means that the whole file is not loaded in memory which conserves resources
and makes the loading process a lot faster. All you have to do is implement the
Use this method when...
load method can take a String containing the file path, or a File object.
What happens when some rows contain more fields than others?
Each data row is passed individually as a What happens when some rows are missing fields?
The OK, how do I get the column headers?
The column headers are simply the first row of data returned.
If the column names are not in the first line, then they are either in a predefined line (say line 3),
so start loading lines from there using
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 one line at a time by implementing the
StringsProvider sp
= new StringsProvider( new String[][] {
{ "1", "one" },
{ "2", "two" },
{ "3", "three" } } );
File csvfile = new File("mydata.csv");
CsvManager csvman = new CsvManager();
csvman.save( csvfile, sp );
// You'll also need this class definition
public static class StringsProvider extends CustomLineProvider {
private String[][] iData;
private int iIndex = 0;
public StringsProvider( String[][] pData ) {
iData = pData;
}
protected boolean hasNextLineImpl() throws Exception {
return iIndex < iData.length;
}
protected String[] nextLineImpl() throws Exception {
String[] line = iData[iIndex];
iIndex++;
return line;
}
}
See the save method description for more details. 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-2008 Ricebridge. All Rights Reserved. | ||||||||||