Well, that depends on your environment or file.
In Unix based system, the newline character is '\n'.
In Windows based systems, the newline character sequence is "\r\n".
In old MacOS systems, the newline character is '\r'.
Lovely, isn't it? :D
Your code would only work in Unix based systems (All the Linux distributions, FreeBSD, modern MacOS etc) and finding the last character in Windows (but not finding the '\r', probably assuming it's part of the valuable text).
You can find out a bit more about newline representations here.