Question: I am new to Spring. I have a Job where it reads the file and writes to the Database. If the number of records in the file are more than 8000, i should not process the file and is hould stop the Job Execution. Please suggest what is the better way to do this.

Answer: 
you can implement StepExecutionListener at itemreader. Then you can get readcount which is corresponds your line number.

```
 public class ExampleItemReader implements ItemReader<String>, StepExecutionListener {

    public synchronized String read() throws Exception {
        return "";
    }

    @Override
    public ExitStatus afterStep(StepExecution executionContext) {
        if (executionContext.getReadCount() > 8000) {
            return ExitStatus.COMPLETED;
        }
        return ExitStatus.EXECUTING;
    }

    @Override
    public void beforeStep(StepExecution arg0) {

    }

}

```

advise reading [spring batch patterns](http://docs.spring.io/spring-batch/reference/html/patterns.html)
Not something specific to spring but there is a class `LineNumberReader` in `java.io`. You can make use of it and its `skip` method to skip a good amount of chars.

Example: 

```
public int getNoOfLines(String fileName) {
   LineNumberReader reader = new LineNumberReader(new FileReader(fileName));
   reader.skip(Integer.MAX_VALUE); //skips those many chars, if you feel your file size may exceed you can use Long.MAX_VALUE
   return reader.getLineNumber();
}

```

This is efficient than just reading the file and counting.