So, I'm reading from a txt file. The file is something like this, separate with a tab "/t"
ID name test date object
1 John pass 9/13 RC_CUST_1
2 John fail 10/13 RC_CUST_1
3 John pass
I'm reading the txt file like this:
String line="";
ArrayList<String> data = new ArrayList<String>();
FileReader fIn;
BufferedReader buff;
fIn = new FileReader("...");
buff = new BufferedReader( fIn );
while( ( line = buff.readLine() ) != null )
{
if(!line.isEmpty())
data.add(line);
}
In late of my code I do that:
ArrayList<String> name1 = new ArrayList<String>();
ArrayList<String> RC1 = new ArrayList<String>();
ArrayList<String> date1 = new ArrayList<String>();
ArrayList<String> pass1 = new ArrayList<String>();
String [] substr2;
for(int k=0;k<data.size();k++)
{
substr2=data.get(k).split("\t");
RC1.add(substr2[4]);
name1.add(substr2[1]);
date1.add(substr2[3]);
pass1.add(substr2[2]);
}
And I have an error because you can see, my ID number 3 has not any date or object. How can I fix that, and how can I know what ID has not a date or an object
I would like for example to print: ID number x has not date or ID number x has not any object if I have a error of this type
"\t"? I would use an arbitrary amount of whitespaces instead:.split("\\s+");... Consider creating a class representing a person or a test (depends) representing your data, a bunch ofArrayLists might get hard to handle later on. Also consider usingjava.nioto access file content, you can simply stream the lines byjava.nio.file.Files.lines(java.nio.file.Path filePath);."\t". I get the error only if a field it's empty. I mean the error is when there when I try to add thesubstr2[x]inArrayList