I am reading a text file abc .txt which is tab delimited as shown below
gfh hgh thf
--- --- ---
fgh sji irj
rhf dhh fhf
kji idj ddt
and I am able to read it successfully (for all the columns in the table I have developed a separate pojo along with getters and setters), the advantage is that I can get the value of complete row through its getters.
Now I have to make sure that no column in the table should be null and if any column value is null, then I should throw a new exception, for example ..
gfh hgh thf
--- --- ---
fgh sji irj //row 1
rhf dhh fhf
kji idj ddt
fgq fio //As seen in this row that second column value is null
Now the approach that I am following is that getting the value row wise in a string as shown below
String n = f.getgfh()+f.gethgh()+f.getthf(); //it will contain the contents of the row 1
make a separate method and will pass this string
private boolean validaterow(String f)
{
}
in this method here I am taking the complete row in a string and inside this method I want to break this string in tokens and then further evaluate those tokens for empty or null , if there are then I will return false
null. What your exact problem? Can you show some code to understand your real problem?null, then you already have it. You can also check if the field is null and throw an exception with a more detailed message for every field. Another option can be done using reflection. Again: there's no exact answer for this, it will depend on your needs.