title: Spring Batch: Pass over names of read-in files to the next step
body: <p>I'm new to Spring Batch and I got started off using Spring Boot &amp; Spring Batch official <a href="https://spring.io/guides/gs/batch-processing/" rel="nofollow noreferrer">tutorial</a>.</p>
  
  <p>The problem I have is that, after reading in some files using spring batch, I want to store the names of those files and remove them in the next step.</p>
  
  <p>I first tried StepExecutionContext to pass data but apparently the data that I wished to pass along was way to big. So I tried saving the name of the files that I read when I initialized my Reader and reading that file in my next step.</p>
  
  <pre><code>@Bean
  public MultiResourceItemReader&lt;Widget&gt; widgetMultiReader() {
      MultiResourceItemReader&lt;Widget&gt; reader = new MultiResourceItemReader&lt;Widget&gt;();
      ClassLoader cl = this.getClass().getClassLoader();
      ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(cl);
      try {
          System.out.println("file:" + dataFileLocation + "Widget*.dat");
          Resource[] resources = resolver.getResources("file:" + dataFileLocation + "Widget*.dat");
          System.out.println("FOUND " + resources.length + " Widget.dat files");
          StringBuilder sb = new StringBuilder();
          for (int i=0; i&lt;resources.length; i++) {
              System.out.println(resources[i].getFilename());
              sb.append(resources[i].getFilename());
              if(i &lt; resources.length-1){
                  sb.append("\n");
              }
          }
          reader.setResources(resources);
          reader.setDelegate(widgetReader());
  
          File tempFolder = new File(dataFileLocation + Constants.TEMP_FOLDER_NAME);
          tempFolder.mkdir();
          File tempFile = new File(tempFolder.getAbsolutePath(), "read_in_files.tmp");
          tempFile.createNewFile();
          FileWriter fileWriter = new FileWriter(tempFile, false);
          fileWriter.write(sb.toString());
          fileWriter.close();
      } catch (IOException e) {
          e.printStackTrace();
      }
      return reader;
  }
  </code></pre>
  
  <p>This was all working really well but turns out if I do this, the code inside the bean will execute automatically even if it's not defined in the job step. This apparently is because of dependency injection (<a href="https://stackoverflow.com/questions/31276011/spring-boot-spring-batch-job-enabled-false-not-able-to-recognize">Spring boot spring.batch.job.enabled=false not able to recognize</a>) </p>
  
  <p>So I have to change my method yet again can you guys help me out here please?</p>
  
  <p>All I want to do is to read in a set of text files, read in the data inside it, store it to the database (this is already done) THEN, remove/archive/move those files in the next step so if there's something like FlatFileParseException, entire job will stop and not remove the files.</p>