通过转换为Array来编辑文件。 [英] Editing files by converting to Array.

查看:64
本文介绍了通过转换为Array来编辑文件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将文件转换为字节数组,以便我可以对其进行一些编辑。我的程序将生成一个82个字符的字符串,如何告诉我的程序打开一个文件并将其粘贴,比方说,偏移100?



我尝试过以下代码:



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:

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



然后:




And then:

data[10] = (byte)09;



现在,我假设这告诉程序在打开的文件中写入偏移量为10的字节09,对吗?但是,在我这样做之后,当我在十六进制编辑器中查看它时,没有09 @ offset 10。我很抱歉,如果这不是它应该做的。



我正在尝试打开.pac文件。这种格式对于你们大多数人来说可能都不熟悉,因为它是一个游戏文件。那么,我可以使用哪种方法打开任何类型的文件?这不是文本文件,我通常使用十六进制编辑器编辑它。



这是一个WinForms应用程序。



我已经做了很多搜索,但是,因为我是编码的新手,我确实感到很困惑。


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.

推荐答案

引用:

现在,我假设这告诉程序在打开的文件中写入偏移量为10的字节09,对吗?

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





不是你把文件的内容存储在字节数组中但是在更改数据后[10]你不保存它











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




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

data[10] = (byte)09;

System.IO.File.WriteAllBytes(filename,data);


这篇关于通过转换为Array来编辑文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆