I am attempting to break a comma-delimited lines in a file for loading the values into an Oracle database. stringtokenizer is fine for getting hold of the values except where there is a null string between the commas i.e ... 1)how do I check for the null string in a line ? 2) how do I check, if i want to ignore some comma-delimiter with in a line ?
You might check out the CSV reader utility, located in the resources section of my site. It uses a simplistic state machine implementation, and comes complete with JUnit tests, so it should be relatively easy to tailor to your needs. Regards, Jeff L.
Try the public StringTokenizer(String str, String delim, boolean returnDelims) constructor. I think that will give you all the commas as tokens. It's a little extra work to throw them away, but you won't miss any empty fields. If you really have CSV, take Jeff up on his code. If you look at how Excel or other programs export to CSV, they add quotes around strings or maybe only strings that contain commas. That gets a little tricky.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi