I would use java.util.Scanner
. It can scan a file for you and rip it into pieces:
Scanner scanner = new Scanner(cFile);
while (scanner.hasNextLine()) {
String curLine = scanner.nextLine().trim();
this.processRow(curLine);
}
private void processRow(String workString) {
Scanner lineScanner = new Scanner(workString);
lineScanner.useDelimiter(",");
// .next goes through the elements
lineScanner.next();
}
Let us know how it goes. A few interesting challenges you might face, depending on the structure of your CSV file (this is why you might need to do some elaborate code here)
It could be:
number,string,string,"String with , inside",String,number
So if you only "escape" the String with , inside you have trouble. If all Strings are in "" then you need to Strip these and you have multiple delimiters to deal with:
Number,"String Number,Number "String","String" String",Number
so it gets a little complicated and you might want to use the byte array and a state to go through the individual lines.
Alternatively you can give OpenCVS a shot