Friday, June 18, 2010

Read Byte Array From File

 //ReadByteArrayFromFile : This function read file from FilePath
        public byte[] ReadByteArrayFromFile(string f_stFilePath)
        {
            //Create Data array
            byte[] l_arData = null;
            //Create FileStream instance in Read mode
            FileStream l_FileStream = new FileStream(f_stFilePath, FileMode.Open, FileAccess.Read);
            //Create BinaryReader Instance
            BinaryReader l_BinaryReader = new BinaryReader(l_FileStream);
            //Calculate Total Number of bytes to be read
            long l_nmTotalBytes = new FileInfo(f_stFilePath).Length;
            //Read Bytes Using BinaryReader Instance
            l_arData = l_BinaryReader.ReadBytes((int)l_nmTotalBytes);
            //Now we have data in DataArray so, just need to close open streams
            l_FileStream.Close();
            l_BinaryReader.Close();
            //return Data array to the calling function
            return l_arData;
        }
Apple iPod touch 32 GB, Case, and Charger Bundle

No comments:

Post a Comment