gw.Write(string) ?

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

    gw.Write(string) ?

    I am getting an extra character at te beginning of the file,
    can someone please check if there is an error in my code?

    Dim fs As FileStream
    fs = New FileStream(Form 1.REGFILE, FileMode.Create New, FileAccess.Writ e)
    Dim gw As New BinaryWriter(fs )
    gw.Write(s)
    gw.Flush()
    gw.Close()
    fs.Close()
  • Herfried K. Wagner [MVP]

    #2
    Re: gw.Write(string ) ?

    "dinny" <nospam> schrieb:[color=blue]
    >I am getting an extra character at te beginning of the file,
    > can someone please check if there is an error in my code?
    >
    > Dim fs As FileStream
    > fs = New FileStream(Form 1.REGFILE, FileMode.Create New, FileAccess.Writ e)
    > Dim gw As New BinaryWriter(fs )
    > gw.Write(s)
    > gw.Flush()
    > gw.Close()
    > fs.Close()[/color]

    Maybe the character is an UTF BOM:

    <URL:http://www.unicode.org/faq/utf_bom.html>

    --
    Herfried K. Wagner [MVP]
    <URL:http://dotnet.mvps.org/>

    Comment

    • Jay B. Harlow [MVP - Outlook]

      #3
      Re: gw.Write(string ) ?

      Dinny,
      Review the help for BinaryWriter.Wr ite(String)!

      Seeing as BinaryWriter is writing a Binary File, it encodes the length of
      the string before it writes the encoded characters of the string. It does
      this so as to allow reading back the same number of characters in
      BinaryReader.Re adString.

      For information on the encoded length see the following:

      BinaryWriter.Wr ite(String):



      Corresponding BinaryReader.Re adString:


      Hope this helps
      Jay


      "dinny" <nospam> wrote in message
      news:%23wcryFQw EHA.2568@TK2MSF TNGP10.phx.gbl. ..[color=blue]
      >I am getting an extra character at te beginning of the file,
      > can someone please check if there is an error in my code?
      >
      > Dim fs As FileStream
      > fs = New FileStream(Form 1.REGFILE, FileMode.Create New, FileAccess.Writ e)
      > Dim gw As New BinaryWriter(fs )
      > gw.Write(s)
      > gw.Flush()
      > gw.Close()
      > fs.Close()[/color]


      Comment

      • Rulin Hong

        #4
        RE: gw.Write(string ) ?

        For process text. Suggest use StreamWriter to replace BinaryWriter.

        Comment

        • dinny

          #5
          Re: gw.Write(string ) ?

          Thanks very much.

          Comment

          Working...