locked
File manipulator class RRS feed

  • Question

  •  

    In my current project I need a file manipulation (biunary) class. Features I'm lloking for is:

    * finding a numeric value in the file
    * adding content of a buffer in a specific offset in the file

    * cut/paste section of the file

     

    and so on... I'm going to code it myself if there isn't an implementation but I'm sure somewhere there is a good implementation of what I want. I googled it and found nothing. So is there an implementation somewhere?

     

    Thanks in advance...

     

    Lovens

    Monday, October 29, 2007 2:17 PM

Answers

  • Hi Lovens,

    So far as I know, you have to read and write the file manually.

    If you want to find a numeric value in the file, you have to use a BinaryReader Class to read the data of the file byte by byte and test if the current read byte is the numeric value you want to find.

    For “adding content of a buffer in a specific offset in the file”, doing this in file is not possible. You can't shorten or stretch a file. Rather, what you can do is resort to creating a new file, and then overwriting the original file with that.

    cut/paste section of the file”, same as the question above.

    And there are several discussions on this issue:

    ·         How to replace some bytes of a binary file

    ·         How Do I...Read and write binary data?

    ·         Delete a line from a text file

    Hope this helps!

    Thanks!

    Wednesday, October 31, 2007 5:57 AM
  • Hi Lovens,

    Actually, the best way to do this is using win32 memory mapping file, but .net did not encapsulate this mechanism.

    Thanks!

    Monday, November 5, 2007 8:25 AM

All replies

  • Hi Lovens,

    So far as I know, you have to read and write the file manually.

    If you want to find a numeric value in the file, you have to use a BinaryReader Class to read the data of the file byte by byte and test if the current read byte is the numeric value you want to find.

    For “adding content of a buffer in a specific offset in the file”, doing this in file is not possible. You can't shorten or stretch a file. Rather, what you can do is resort to creating a new file, and then overwriting the original file with that.

    cut/paste section of the file”, same as the question above.

    And there are several discussions on this issue:

    ·         How to replace some bytes of a binary file

    ·         How Do I...Read and write binary data?

    ·         Delete a line from a text file

    Hope this helps!

    Thanks!

    Wednesday, October 31, 2007 5:57 AM
  • Ok thanks Feng but I already know how to do all the features I want, I just wanted to know if the solution was already implemented. Oh well time to code now...

    Thansk

     

    Lovens

     

    Wednesday, October 31, 2007 12:02 PM
  • Hi Lovens,

    Actually, the best way to do this is using win32 memory mapping file, but .net did not encapsulate this mechanism.

    Thanks!

    Monday, November 5, 2007 8:25 AM