I have a directory with several text files in it, each of which contains a line of text that is delimited by commas. I am expecting to find 4 tokens as I read from each file while creating a String array. So, a normal line in the text file would be like this:
cat,dog,876358293472,884459654596
But I want to account for files that are not formed as I expect. Or if the file is empty. For instance, a file might have only this:
cat,dog,
or
cat,0000000000000
I have some code to handle the token length but am not sure how to account for cases where the file isn't formatted like I expect. Here's what I have so far:
while((line = br.readLine()) != null) {
try {
String [] tokens = line.trim().split(",");
if (tokens.length != 4) {
return null;
}
Are there other checks I should do in addition to 'token.length'?