C# beginner FileStream help please
Hi guys,
I am currently trying to read the first 512 bytes of a series of files into array entries for future use. i.e.
files [file 1 contents]
files [file 2 contents] etc etc...
So far with my very limited time with C# (I started yesterday!) I have cobbled this together which will pick the files from a folder, and read the first 512 bytes to console.write() just to show me that it is getting the data.
I know in C I could just use pointers, but I understand they are not really used in #?
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
class Program
{
static void Main()
{
// Put all exe files in root directory into array.
string[] array2 = Directory.GetFiles(@"C:\Dev-Cpp\", "*.EXE");
// Display all BIN files.
Console.WriteLine(@"C:\Dev-Cpp\");
Console.WriteLine("--- EXE Files: ---");
foreach (string name in array2)
{
Console.WriteLine(name);
}
for (int print = 0; print < array2.Length; print++)
{
FileStream myFStream = new FileStream(array2[print], FileMode.OpenOrCreate, FileAccess.ReadWrite);
Console.WriteLine("Contents of file {0}: ", array2[print]);
for (int i = 0; i < 512; i++)
{
Console.Write(myFStream.ReadByte());
//debugging space to print each byte to screen
Console.Write(" ");
}
Console.WriteLine();
myFStream.Close();
}
Console.ReadKey();
}
}
Any help, advice, links to relevant content greatly appreciated :)
Cheers,
Ben