Good day to all, please help me figure out how to add data to a binary file? There is a code that writes the value to the file:
using (BinaryWriter WriteNr = new BinaryWriter( File.Open( path2, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite ) )) { WriteNr.Write(Line); WriteNr.Close(); } But when you add a new record, the old one is erased, ie the file is overwritten, how to make the old records remain and the new ones added? Please help me figure it out.
When reading a file, only the latest data still gets, here's how I read the file:
using (BinaryReader reader2 = new BinaryReader( File.Open( path2, FileMode.Open, FileAccess.Read, FileShare.ReadWrite ) )) { while (reader.PeekChar() > -1) { Nr++; Line = reader.ReadInt32();} I need to read from beginning to end and write down if there are no matches, but I cannot check it because the data is constantly taken, the last ones are written, and not in order.