Skip to content

Instantly share code, notes, and snippets.

@traktraktrugui
Created October 17, 2013 03:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save traktraktrugui/7018700 to your computer and use it in GitHub Desktop.
Save traktraktrugui/7018700 to your computer and use it in GitHub Desktop.
Get a last line from a text file
void Main()
{
string fileName = @"c:\windows\setupapi.log";
byte[] array = new byte[100];
using (FileStream fs = new FileStream(fileName, FileMode.Open))
{
if (fs.CanSeek && fs.Length > 100)
{
fs.Position = fs.Length - 100;
fs.Read(array, 0, 100);
}
}
Encoding enc = new ASCIIEncoding();
string line = enc.GetString(array);
Console.Write(line);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment