Is there a way to get the last character of a file without reading line by line?

I need to get the last character of the file. It can be a line break or one of many special characters. Can I get this character indiscriminately throughout the file? Or is there a way I can read an entire file into a line without worrying about line breaks?

I essentially need to split the contents of the file based on the last character of the file. Therefore, if it is a line break, I split the line into "\ n".

+3
source share
3 answers
string s = File.ReadAllText("test.txt");
string[] split = s.Split(s[s.Length - 1]);
+4
source

You can search () at the end of the file - 1, and then just read () one byte.

, Stream .

+7

StreamReader ReadToEnd(). .

0
source

Source: https://habr.com/ru/post/1729575/


All Articles