When you are processing a file, you may have a logical need to only process it when it is not empty. You can check if a file is empty in two ways.
The first way is to hard code a solution via a tJava or tJavaRow. For example, check if a file is empty on a tJava and put the result to a global variable.
java.io.File newFile = new java.io.File("D:/files/test.txt");
if (newFile.length() == 0) {
System.out.println("File is empty ...");
globalMap.put("isEmpty", true);
} else {
System.out.println("File is not empty ...");
globalMap.put("isEmpty", false);
}
Another way is to use the tFileProperties component, which outputs the main properties of the processed file, where the size property is calculated as the size of the file in bytes. If it is 0, the file is empty.
For example...
tFileProperties--main-->tJavaRow--runIf--next processing on tJavaRow:
if(input_row.size==0){
globalMap.put("isEmpty", true);
}else{
globalMap.put("isEmpty", false);
}
As shown in the above code and screenshot, we usually put the result to global variable for use later. You can use the global variable as the condition of a RunIf link to decide whether it needs to trigger the next processing.