Reading binary file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dave

    #1

    Reading binary file

    Can someone tell me the best way to read fixed length string content from a
    binary file. There are no delimiters between strings. I only know the
    starting byte and that each string is 64 Bytes long. I was doing something
    like the following but it seems as though I must be doing this the hard way?

    Thanks in advance for your help.

    Dave

    BinaryReader *binaryInput;

    FileStream *fileInput;

    __wchar_t tHold;

    String *testing;

    fileInput = new FileStream( filename, FileMode::Open, FileAccess::Rea d );

    binaryInput = new BinaryReader( fileInput );

    // find beginning of comment data

    fileInput->Seek( AppData->CommentStartBy te , SeekOrigin::Beg in );

    for ( int i=1; i <= AppData->CommentByteLen ; i++ ){

    tHold = binaryInput->ReadChar();

    testing = String::Concat( testing, tHold.ToString( ) );

    }


  • Dave

    #2
    Re: Reading binary file

    Sorry, The AppData is just a udt to hold all of the information required to
    find data in thes files. Also, the files are data files from an old program
    I developed in another language long ago. Now I need to read these files
    and convert them to a different structure for a new version of the same
    program to be written in MS VC++.NET.

    Thanks again for the help.

    Dave

    "Dave" <vb_remove@4sco tts.com> wrote in message
    news:OR6mlDU6DH A.2392@TK2MSFTN GP11.phx.gbl...[color=blue]
    > Can someone tell me the best way to read fixed length string content from[/color]
    a[color=blue]
    > binary file. There are no delimiters between strings. I only know the
    > starting byte and that each string is 64 Bytes long. I was doing[/color]
    something[color=blue]
    > like the following but it seems as though I must be doing this the hard[/color]
    way?[color=blue]
    >
    > Thanks in advance for your help.
    >
    > Dave
    >
    > BinaryReader *binaryInput;
    >
    > FileStream *fileInput;
    >
    > __wchar_t tHold;
    >
    > String *testing;
    >
    > fileInput = new FileStream( filename, FileMode::Open, FileAccess::Rea d );
    >
    > binaryInput = new BinaryReader( fileInput );
    >
    > // find beginning of comment data
    >
    > fileInput->Seek( AppData->CommentStartBy te , SeekOrigin::Beg in );
    >
    > for ( int i=1; i <= AppData->CommentByteLen ; i++ ){
    >
    > tHold = binaryInput->ReadChar();
    >
    > testing = String::Concat( testing, tHold.ToString( ) );
    >
    > }
    >
    >[/color]


    Comment

    Working...