0

I'm trying to open an existent file save a bytes in the start of it to later read them.

How can I do that? Because the "&" operand isn't working fo this type of data.

I'm using Encoding.UTF8.GetBytes("text") to convert info to bytes and then add them.

Help Please.

1
  • 1
    The title seems to indicate something different from the actual question. Please clarify. Jan 31, 2010 at 4:53

1 Answer 1

4

You cannot add to or remove from the beginning of a file. It just doesn’t work. Instead, you need to read the whole file, and then write a new file with the modified data. (You can, however, replace individual bytes or chunks of bytes in a file without needing to touch the whole file.)

Secondly,

I'm using Encoding.UTF8.GetBytes("text") to convert info to bytes and then add them.

You’re doing something wrong. Apparently you’ve read text data from the file and are now trying to convert it to bytes. This is the wrong way of doing it. Do not read text from the file, read the bytes directly (e.g. via My.Computer.FileSystem.ReadAllBytes). Raw byte data and text (i.e. String) are two fundamentally different concepts, do not confuse them. Do not convert needlessly to and fro.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.