using System; using System.IO; using System.Collections; namespace Applica { static class Program { static void Main(string[] args) { DirectoryInfo da = new DirectoryInfo("C:\\Fol"); if (!da.Exists) { Console.WriteLine("The folder '{0}' does not exist.", da.FullName); return; } FileInfo[] Arr = da.GetFiles(); if (Arr.Length == 0) { Console.WriteLine("There are no files in the folder '{0}'.", da.FullName); return; } FileInfo ap = Arr[Arr.Length - 1]; long Totbyte = ap.Length; string filePath = ap.FullName; Console.WriteLine("Total Bytes = {0} bytes", Totbyte); const int BufferSize = 1024; byte[] buffer = new byte[BufferSize]; string destinationPath = Path.Combine("C:\\check", Path.GetFileName(filePath)); using (Stream input = File.OpenRead(filePath)) using (Stream output = File.OpenWrite(destinationPath)) { int bytesRead; while ((bytesRead = input.Read(buffer, 0, BufferSize)) > 0) { for (int count = 0; count < bytesRead; count++) { byte theByte = buffer[count]; string theByteInBinary = Convert.ToString(theByte, 2).PadLeft(8, '0'); Console.WriteLine("{0} = {1}", theByteInBinary, theByte); } output.Write(buffer, 0, bytesRead); } } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)