I'm trying to output binary file information something like this:
File size : 5 KB
Start : 0x00
End: 0x 20

But I don't really know how to output the end of file.
Hope somebody can help me.
Thanks.

 public static void binaryread(string file)
            {
                FileStream fs;
                BinaryReader br;
                FileInfo f;
              try
                {              
                    fs = new FileStream(file, FileMode.Open, FileAccess.Read);
                    br = new BinaryReader(fs);
                    f = new FileInfo(file);
                    long s1 = f.Length;

                    //string start = Convert.ToString(fs.Seek(0, SeekOrigin.Begin));
                    //string end = Convert.ToString(fs.Seek(0, SeekOrigin.End));                  

                    Console.WriteLine("File size  : " + FormatBytes(s1));
                    Console.WriteLine("Start      : " + HexConverted(start));
                    Console.WriteLine("End        : " + HexConverted(end));  
                 //}
                }

             }

You could always read the file into a byte array using something like

byte [] MyArray = File.ReadAllBytes(fileName);

Then, if I am reading your code correctly

Console.WriteLine("Start : " + HexConverted(MyArray[0]));
Console.WriteLine("End : " + HexConverted(MyArray[MyArray.Length - 1]));

That should give you the first and last byte of the file, which you can of course convert to a Hex value.

One thing (and I pretty sure this will happen, but you'd need to test to make sure), the start value might return the very first byte of the file, which would be the file header (so if it was like a txt file, you wouldn't get the first letter of the file, but header data)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.