StreamReader vs BinaryReader

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

    StreamReader vs BinaryReader

    Hi sharpies,

    Quick question. I have a file with 4 column data with line terminating
    with CRLF.

    name~age~data~m onth

    Where the data is binary data. Most of the time it will be .... (binary
    value of FFFFFFF). When I used the stream reader, it read all the
    records correctly (used readline). But the problem is, it doesn't put
    my data field with actual data, instead it put empty data. So if I have
    a row

    dbc~34~......~3 (Where .... binary value is FFFFFFFFF)

    the program reads in dbc~34~~3.

    Does anyone know why stream reader is skipping that value? I haven't
    tried with binary reader yet. I will try, but just curious why
    streamreader doesn't like the value.

    Thanks/
    DBC User

  • David Browne

    #2
    Re: StreamReader vs BinaryReader


    "DBC User" <ksunair@gmail. com> wrote in message
    news:1110562472 .780942.154290@ l41g2000cwc.goo glegroups.com.. .[color=blue]
    > Hi sharpies,
    >
    > Quick question. I have a file with 4 column data with line terminating
    > with CRLF.
    >
    > name~age~data~m onth
    >
    > Where the data is binary data. Most of the time it will be .... (binary
    > value of FFFFFFF). When I used the stream reader, it read all the
    > records correctly (used readline). But the problem is, it doesn't put
    > my data field with actual data, instead it put empty data. So if I have
    > a row
    >
    > dbc~34~......~3 (Where .... binary value is FFFFFFFFF)
    >
    > the program reads in dbc~34~~3.
    >
    > Does anyone know why stream reader is skipping that value? I haven't
    > tried with binary reader yet. I will try, but just curious why
    > streamreader doesn't like the value.
    >[/color]


    You can't have a lines terminated by CRLF and binary data. What if 0xDA
    appears in the binary data?

    For such a file, just open a FileStream and handle it yourself.

    David


    Comment

    • DBC User

      #3
      Re: StreamReader vs BinaryReader

      Thanks but my question is "is there a reason, why Streamreader is
      skipping the data?" I got it working with binarystream.

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: StreamReader vs BinaryReader

        DBC User <ksunair@gmail. com> wrote:[color=blue]
        > Hi sharpies,
        >
        > Quick question. I have a file with 4 column data with line terminating
        > with CRLF.
        >
        > name~age~data~m onth
        >
        > Where the data is binary data. Most of the time it will be .... (binary
        > value of FFFFFFF). When I used the stream reader, it read all the
        > records correctly (used readline). But the problem is, it doesn't put
        > my data field with actual data, instead it put empty data. So if I have
        > a row
        >
        > dbc~34~......~3 (Where .... binary value is FFFFFFFFF)
        >
        > the program reads in dbc~34~~3.
        >
        > Does anyone know why stream reader is skipping that value? I haven't
        > tried with binary reader yet. I will try, but just curious why
        > streamreader doesn't like the value.[/color]

        StreamReaders are meant for reading text data, not binary data.
        Depending on which encoding is being used, StreamReader is likely to be
        reading *something*, but it may be unprintable. Which encoding are you
        using?

        --
        Jon Skeet - <skeet@pobox.co m>
        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

        If replying to the group, please do not mail me too

        Comment

        Working...