Read file from end to start
I am trying to build a little tool for our messaging (WCF) component. The idea is to give responses based on previous trace logs for testing purposes. As the SOAP messages are very big we tend to have huge trace files. What i want to do is read the traces from end to start开发者_JS百科 line by line (newest to oldest) in order to build my responses. Anyone has any idea how i can do that in .NET?. It seems that FileStream class supports only forward reading.
If these are text files, I have a ReverseLineReader
(or some such) in MiscUtil which you may find useful. It only supports certain encodings (Unicode, UTF-8 or any fixed-single-byte encoding) but hopefully that'll be enough for you.
It returns the strings via an iterator, so you can use LINQ to limit how many you read etc, and they're read lazily.
I assume you don't actually want to read the whole file? If you do, I'd suggest using File.ReadAllLines
and then reversing the resultant array :)
精彩评论