I have a 16gb data file, what I need is edit some bytes at the specific binary address of the file. I'm curious is it possible to accomplish or not, because of the huge size of the file, as I understand BinaryWriter class will open this file first then write to it, so I'm guessing that it will take a lot of time for a system to open it then write to it.
Asked
Active
Viewed 39 times
0
-
This question is too broad. Editing bytes in a file can mean *anything*. Reading and writing to files is the job of a Stream anyway, eg a FileStream. BinaryWriter, as the docs explain, is meant to serialize primitive types using a specific binary format. It can't work by itself, it needs a stream – Panagiotis Kanavos Aug 07 '18 at 07:24
-
Check [File and Stream I/O](https://learn.microsoft.com/en-us/dotnet/standard/io/) in the docs. BinaryReader/Writer, StreamReader/Writer are meant to handle specific formats, not modify bytes. What is the format of the file you want to modify? There may be libraries that can handle that specific format so you don't have to work directly with streams and bytes – Panagiotis Kanavos Aug 07 '18 at 07:26
-
@PanagiotisKanavos i mean if i want edit bytes at address 501190 501191 501192 – James_BK Aug 07 '18 at 07:29
-
Use a stream, seek to that position and read/write the bytes. That's explained in the docs. People never want to do that though, they want to work with *specific* formats, like text, csv, xml or Avro, Parquet for large data. There are libraries that can handle any format. What is the format of that file? – Panagiotis Kanavos Aug 07 '18 at 07:32
-
A more advanced option is to use [Memory-mapped files](https://learn.microsoft.com/en-us/dotnet/standard/io/memory-mapped-files) and treat the mapped file as if it were a byte array – Panagiotis Kanavos Aug 07 '18 at 07:33
-
@PanagiotisKanavos its .img – James_BK Aug 07 '18 at 07:35