How to read file line by line by CRLF

I have the following file:

enter image description here

and following code:

        Scanner scanner = new Scanner(new FileReader(new File(file.txt)));
        scanner.useDelimiter("rn");
        int i = 0;
        while (scanner.hasNext()) {
            scanner.nextLine();
            i++;

        }
        System.out.println(i);

it returns 5.

expected result 2.

What do I wrong?

I want to split by CRLF only (not LF).

Source: java

Leave a Reply