Click here to Skip to main content
15,919,245 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to convert a file into a byte array so that I can make some edits to it. My program is going to produce a 82 character string, how can I tell my program to open up a file and paste it at, let's say, offset 100?

I have tried the following code:

C#
byte [] data = System.IO.File.ReadAllBytes(filename)

And then:

C#
data[10] = (byte)09;

Now, I'm assuming that this is telling the program to write the byte 09 at offset 10 in the opened file, correct? However, after I do that, there is no 09 @ offset 10 when I look at it in a hex editor. I'm sorry if that's not what it was supposed to do.

I'm trying to open a .pac file. This format may seem unfamiliar to most of you as it is a game file. So, what method could I use that could open any type of file? This is not a text file, I usually edit this using a hex editor.

This is a WinForms application.

I've done a lot of searching, but, because I'm new to coding, I do get confused quite a bit.
Posted

1 solution

Quote:
Now, I'm assuming that this is telling the program to write the byte 09 at offset 10 in the opened file, correct?


No you store the content of the file in a byte array but after changing data[10] you don't save it




C#
byte [] data = System.IO.File.ReadAllBytes(filename);

data[10] = (byte)09;

System.IO.File.WriteAllBytes(filename,data);
 
Share this answer
 
v2
Comments
Miztah Raza 11-Sep-13 9:58am    
That did it!
Thanks for the help, dude. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900