title: Spring Batch - FlatFileItemWriter write to a file, close it, write to new file
body: <p>So I have a custom class that extends FlatFileItemWriter that I am using to write a CSV file. Based on some condition I want to finish with my first file and then write to a new file. Is there a way to do this with FlatFileItemWriter?</p>
  
  <p>Here is an example of my code:</p>
  
  <pre><code>@Override
  public void write(List&lt;? extends MyObject&gt; items) throws Exception {
      ExecutionContext stepContext = this.stepExecution.getExecutionContext();
      int currentFileIncrememnt = (int) stepContext.get("currentFileIncrement");
      if(currentFileIncrement== fileIncrement) {
          super.write(items);
      }
      else {
          super.close();
          fileIncrement = currentFileIncrement;
          super.setHeaderCallback(determineHeaderCallback());
          super.setResource(new FileSystemResource("src/main/resources/" + fileIncrement+ ".csv"));
          super.setShouldDeleteIfExists(true);
          DelimitedLineAggregator&lt;MyObject&gt; delLineAgg = new DelimitedLineAggregator&lt;&gt;();
          delLineAgg.setDelimiter(",");
          BeanWrapperFieldExtractor&lt;MyObject&gt; fieldExtractor = new BeanWrapperFieldExtractor&lt;&gt;();
          fieldExtractor.setNames(new String[] {"id", "amount"});
          delLineAgg.setFieldExtractor(fieldExtractor);
          super.setLineAggregator(delLineAgg);
          super.write(items);
      }
  }
  </code></pre>