Identifying the last line in the flat file/Count the number of lines in a flat file

Hi,

I’m working on Dynamics 365 for Finance and Operations Update 11.

Below is the flat file that I’m using.

pastedimage1514189563588v1.png

I would like to read and process only 2nd , 3rd and 4th lines . I want to ignore the first and last lines of the file irrespective of number of lines in the file .

I’m using AsciiStreamIo class for reading the contents of flat file .

I have used inRecordDelimiter(#delimiterCRLF);

Please advise me on how to identify the last line / Count the total number of lines in the flat file so that i can ignore the first and last line while processing.

You can always check if there is another line before processing the current line. Somehow like this:

currentLine = file.read();
currentLine = file.read();
if (!currentLine)
{
    // fail fast
}
    
do
{
    nextLine = file.read();
    if (nextLine)
    {
        process(currentLine);
    }
    currentLine = nextLine;
}
while (currentLine);