Creating and writing files depending on the input data
Sometimes it is required that multiple files are written from a single data source where the file name is dependent upon the data held within the row. This recipe shows how this can be achieved.
Getting ready
Open the jo_cook_ch08_0140_filesFromInputData
job.
How to do it...
The steps for creating and writing files depending on the input data are as follows:
Run the job, and you will see that the file
dummy.txt
has been created and populated with six rows.Open the
tJavaRow
component, and you will see that the move of data from input to output has already been performed.Add in the following code after the generated code:
// test for change of input_row.key if (Numeric.sequence(input_row.key, 1, 1) == 1 ) { outtFileOutputDelimited_1.flush(); // if this is the first record then do not flush and close - do not want to create dummy.txt // otherwish if sequence > 1 then we will close the previous file if(Numeric.sequence("all", 1...