im trying to read a binary file into my own hex editor using a datagridview.
this was my initial approach
FileStream RawD = new FileStream(ECUFileName, FileMode.Open, FileAccess.Read);
BinaryReader RawB = new BinaryReader(RawD);
then i've tried just the binary reader as well...
now i'm using
MemoryMappedFile RawD = MemoryMappedFile.CreateFromFile(ECUFileName);
MemoryMappedViewStream stream = RawD.CreateViewStream();
BinaryReader RawB = new BinaryReader(stream);
all i want the code to do is read decimals and put it in a datagridview. a 2mb file takes forever.
while (RawB.BaseStream.Position <= RawB.BaseStream.Length)
{
if (term == true) break;
DataGridViewRow row = (DataGridViewRow)DataG.Rows[0].Clone();
DataG.Rows.Add(row);
for (int P = 0; P < I; P++)
{
if (RawB.BaseStream.Position == RawB.BaseStream.Length) break;
Int16 Byte = RawB.ReadInt16();
string ByteStr = string.Format("{0}",Byte);
DataG[P, X].Value = ByteStr;
DataG[P, X].ReadOnly = true;
string ADR = string.Format("{0:x6}", X * 10); ;
DataG.Rows[X].HeaderCell.Value = ADR;
DataG.FirstDisplayedScrollingRowIndex = DataG.FirstDisplayedScrollingRowIndex + 1;
if (term == true) break;
}
i've just tried this, seems a bit quicker
byte[] bytes = File.ReadAllBytes(ECUFileName);
for (int i=0; i <= bytes.Length; i++)
{
string result = Convert.ToString(bytes[i]);
richTextBox1.AppendText(result);
}
be hex editor cant be used for what i intend to do, so i have to manually do it.
i have read tons of articles where people say read AllBytes with the file method, to have the file stored in memory, when i tried the file method, it didn't work fast as well.