title: Spring batch Save skipped reader lines in rejection file
body: <p>I want to rewrite skipped reader lines in output rejection file, thanks.</p>
  
  <p>My code :</p>
  
  <pre><code>public class JobPerson {
  
      @Autowired
      private JobBuilderFactory jobs;
  
      @Autowired
      private StepBuilderFactory steps;
  
  
      @Bean
      public ItemReader&lt;Person&gt; itemReader() {
          FlatFileItemReader&lt;Person&gt; reader = new FlatFileItemReader&lt;Person&gt;();
          reader.setResource(new ClassPathResource("user.csv"));
          reader.setLineMapper(new DefaultLineMapper&lt;Person&gt;() {{
              setLineTokenizer(new DelimitedLineTokenizer(";") {{
                  setNames(new String[] {"firstName", "lastName", "age" });
              }});
              setFieldSetMapper(new BeanWrapperFieldSetMapper&lt;Person&gt;() {{
                  setTargetType(Person.class);
              }});
          }});
          return reader;
      }
  
  
  
      @Bean
      public ItemWriter&lt;Person&gt; itemWriter() {
          return items -&gt; {
              int i=0;
              for (Person item : items) {
                  i++;
  
                  System.out.println(i+". Nom = " + item.getFirstName()+". Prenom = " + item.getLastName());
              }
          };
      }
  
      @Bean
      public ItemProcessor&lt;Person, Person&gt; itemProcessor() {
          return item -&gt; {
              String stritem=item.toString();
              String[] splitArray = stritem.split(";"); // tableau de chaînes
              int lineData = splitArray.length;
              //if (lineData&lt;2)
  
              if (item.equals("Eric")) {
                  throw new IllegalArgumentException("Wanted!");
              }
              return item;
          };
      }
  
      @Bean
      public Step step() {
          return steps.get("step")
                  .&lt;Person, Person&gt;chunk(5)
                  .reader(itemReader())
                  .processor(itemProcessor())
                  .writer(itemWriter())
                  .faultTolerant()
                  .skip(IllegalArgumentException.class)
                  .skipLimit(100)
                  .listener(new MySkipListener())
                  .skip(Exception.class)
                  .build();
      }
  
      @Bean
      public Job job() {
          return jobs.get("job")
                  .start(step())
                  .build();
      }
  
      public static class MySkipListener implements SkipListener&lt;Person, Person&gt; {
  
          @Override
          public void onSkipInRead(Throwable t) {
              System.err.println("On Skip in Read Error : " + t.getMessage());
          }
  
          @Override
          public void onSkipInWrite(Person item, Throwable t) {
              System.out.println("Item " + item + " was skipped due to: " + t.getMessage());
          }
  
          @Override
          public void onSkipInProcess(Person item, Throwable t) {
              System.out.println("Item " + item + " was skipped due to: " + t.getMessage());
          }
      }
  }
  </code></pre>
  
  <p>Lines to rewrite( lines in red): </p>
  
  <p><a href="https://i.stack.imgur.com/M3IyJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M3IyJ.png" alt="lines writing with red"></a></p>
  
  <p>=> On Skip in Read Error : Parsing error at line: 2 in resource=[class path resource [user.csv]], input=[Eric;Bonneton;]
  On Skip in Read Error : Parsing error at line: 3 in resource=[class path resource [user.csv]], input=[sdqsdqs;]</p>