tom jones

tom jones

  • NA
  • 18
  • 11k

ReadAllBytes Method of the File Class PROBLEM

Feb 10 2014 10:44 AM
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Applica
{
    class Program
    {
        static void Main(string[] args)
        {
            long Totbyte = 0;//file length initialize to 0
            DirectoryInfo da = new DirectoryInfo("C:\\Folder");//local file on the computer
            FileInfo[] Arr = da.GetFiles();
            foreach (FileInfo ap in Arr)
                Totbyte = ap.Length;//real file length on local computer
            Console.WriteLine("Total Bytes = {0} bytes", Totbyte);//the code works great up to this point
            
            //want to set up an array for the exact file length above and read all bytes into the array
            //not sure of what I am doing below, but its not working out
            string temPath = Path.GetTempFileName();
            string temPath2 = Path.GetTempFileName();
                if (File.Exists(temPath))
                {
                    byte[Totbyte] data = File.ReadAllBytes(temPath);
                    File.WriteAllBytes(temPath2, data);
                }
        }
    }
}

Answers (7)