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: 
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.
I'm assuming that the records in your file are not fixed length. If so, File.length() will easily calculate the number of records in the file.

If not, does it need to be exactly 8000 or around 8000? If it's a rough limit, I would get an average record length for these files and then use File.length() to estimate the number of records.