CsvReader trouble

73 views
Skip to first unread message

Terje Halvorsen

unread,
Sep 29, 2012, 11:24:20 AM9/29/12
to csv...@googlegroups.com
Hi,

I have this code in my Java program:

String filename = textFile.getText();

try {

CsvReader cust = new CsvReader(filename);

cust.readHeaders();

while (cust.readRecord())
{
String name = cust.get(1);
String street = cust.get(2);
String zip = cust.get(3);
String city = cust.get(4);

System.out.println(name + ":" + street + ":" + zip + ":" + city);
}

cust.close();

} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

When I run a debugger on this, it reads the file, but it doesn't print... The string variables are empty!
 What could I be missing? 

shriop

unread,
Sep 29, 2012, 3:55:19 PM9/29/12
to csv...@googlegroups.com
it could be a bunch of things. what does getColumnCount() return? how many times does the while loop run? you're actually grabbing the value of the second column to put into your name variable, because the parser is 0 based, and you're using the default constructor which specifies csv, so if you gave it a tab delimited file, it wouldn't find a comma, and the entire record would be in the first column, which you're not currently even looking at.

Bruce Dunwiddie

Anuj Bhatt

unread,
Sep 29, 2012, 3:58:41 PM9/29/12
to csv...@googlegroups.com
Given that he's printing it out with ":", I would think it's the latter.

Anuj
--
You received this message because you are subscribed to the Google Groups "CSVChat" group.
To view this discussion on the web visit https://groups.google.com/d/msg/csvchat/-/WcU92vC26mwJ.
To post to this group, send email to csv...@googlegroups.com.
To unsubscribe from this group, send email to csvchat+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/csvchat?hl=en.
Reply all
Reply to author
Forward
0 new messages