BinaryWriter and filesize limit. Is there any?

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

    #1

    BinaryWriter and filesize limit. Is there any?

    Hi,
    In my app, I open a file using a FileStream then pass it to a
    BinaryWriter. I then use the BinaryWriter instance to write to my file. But
    a problem arose : The file never gets bigger than 1kb. The code calls the
    bw.write(TheVal ue), but nothing is written after 1kb. I'm I missing
    something?

    Here's the way I create my FileStream and BinaryWriter :

    Filename = System.Environm ent.CurrentDire ctory() & "\msec.dat"
    fs = System.IO.File. OpenWrite(Filen ame)
    bw = New System.IO.Binar yWriter(fs)

    When I write I do:

    bw.write(TheVal ueToWrite)

    And when done writing, I do :

    bw.close
    fs.close

    Am I missing something?

    Thanks

    ThunderMusic


  • Scott Swigart

    #2
    RE: BinaryWriter and filesize limit. Is there any?

    What's "TheValueToWrit e" defined as? Are you just writing one value?

    Scott Swigart
    VB - MVP

    "ThunderMus ic" wrote:
    [color=blue]
    > Hi,
    > In my app, I open a file using a FileStream then pass it to a
    > BinaryWriter. I then use the BinaryWriter instance to write to my file. But
    > a problem arose : The file never gets bigger than 1kb. The code calls the
    > bw.write(TheVal ue), but nothing is written after 1kb. I'm I missing
    > something?
    >
    > Here's the way I create my FileStream and BinaryWriter :
    >
    > Filename = System.Environm ent.CurrentDire ctory() & "\msec.dat"
    > fs = System.IO.File. OpenWrite(Filen ame)
    > bw = New System.IO.Binar yWriter(fs)
    >
    > When I write I do:
    >
    > bw.write(TheVal ueToWrite)
    >
    > And when done writing, I do :
    >
    > bw.close
    > fs.close
    >
    > Am I missing something?
    >
    > Thanks
    >
    > ThunderMusic
    >
    >
    >[/color]

    Comment

    • ThunderMusic

      #3
      Re: BinaryWriter and filesize limit. Is there any?

      hi,
      no, I'm not writing just 1 value... the "TheValueToWrit e" was just a name I
      put there because it could be almost any base type : string, bit, byte,
      int16, int32, int64, et al. I go through many steps and would have to write
      from 2k to about 500k (I don't think it will go higher than that, but it
      could).

      For now, I write almost just strings, int32 and booleans but it could be
      anything...

      thanks

      ThunderMusic

      "Scott Swigart" <scott@swigartc onsulting.com> a écrit dans le message de
      news:26290343-F122-4206-A26D-49684C420A7E@mi crosoft.com...[color=blue]
      > What's "TheValueToWrit e" defined as? Are you just writing one value?
      >
      > Scott Swigart
      > VB - MVP
      >
      > "ThunderMus ic" wrote:
      >[color=green]
      > > Hi,
      > > In my app, I open a file using a FileStream then pass it to a
      > > BinaryWriter. I then use the BinaryWriter instance to write to my file.[/color][/color]
      But[color=blue][color=green]
      > > a problem arose : The file never gets bigger than 1kb. The code calls[/color][/color]
      the[color=blue][color=green]
      > > bw.write(TheVal ue), but nothing is written after 1kb. I'm I missing
      > > something?
      > >
      > > Here's the way I create my FileStream and BinaryWriter :
      > >
      > > Filename = System.Environm ent.CurrentDire ctory() & "\msec.dat"
      > > fs = System.IO.File. OpenWrite(Filen ame)
      > > bw = New System.IO.Binar yWriter(fs)
      > >
      > > When I write I do:
      > >
      > > bw.write(TheVal ueToWrite)
      > >
      > > And when done writing, I do :
      > >
      > > bw.close
      > > fs.close
      > >
      > > Am I missing something?
      > >
      > > Thanks
      > >
      > > ThunderMusic
      > >
      > >
      > >[/color][/color]


      Comment

      • Scott Swigart

        #4
        Re: BinaryWriter and filesize limit. Is there any?

        There shouldn't be anything special beyond what you're doing. Here's a
        console app that writes out about 4MB using the same technique.

        Imports System.IO

        Module Module1

        Sub Main()
        Dim data As String = "01234567890123 456789012345678 90123456789"
        Dim filename As String = System.Environm ent.CurrentDire ctory() &
        "\msec.dat"
        Dim fs As Stream = File.Open(filen ame, FileMode.Create ,
        FileAccess.Writ e)
        Dim b As New BinaryWriter(fs )

        For i As Integer = 1 To 100000
        b.Write(data)
        Next

        b.Close()
        fs.Close()
        End Sub

        End Module


        "ThunderMus ic" wrote:
        [color=blue]
        > hi,
        > no, I'm not writing just 1 value... the "TheValueToWrit e" was just a name I
        > put there because it could be almost any base type : string, bit, byte,
        > int16, int32, int64, et al. I go through many steps and would have to write
        > from 2k to about 500k (I don't think it will go higher than that, but it
        > could).
        >
        > For now, I write almost just strings, int32 and booleans but it could be
        > anything...
        >
        > thanks
        >
        > ThunderMusic
        >
        > "Scott Swigart" <scott@swigartc onsulting.com> a écrit dans le message de
        > news:26290343-F122-4206-A26D-49684C420A7E@mi crosoft.com...[color=green]
        > > What's "TheValueToWrit e" defined as? Are you just writing one value?
        > >
        > > Scott Swigart
        > > VB - MVP
        > >
        > > "ThunderMus ic" wrote:
        > >[color=darkred]
        > > > Hi,
        > > > In my app, I open a file using a FileStream then pass it to a
        > > > BinaryWriter. I then use the BinaryWriter instance to write to my file.[/color][/color]
        > But[color=green][color=darkred]
        > > > a problem arose : The file never gets bigger than 1kb. The code calls[/color][/color]
        > the[color=green][color=darkred]
        > > > bw.write(TheVal ue), but nothing is written after 1kb. I'm I missing
        > > > something?
        > > >
        > > > Here's the way I create my FileStream and BinaryWriter :
        > > >
        > > > Filename = System.Environm ent.CurrentDire ctory() & "\msec.dat"
        > > > fs = System.IO.File. OpenWrite(Filen ame)
        > > > bw = New System.IO.Binar yWriter(fs)
        > > >
        > > > When I write I do:
        > > >
        > > > bw.write(TheVal ueToWrite)
        > > >
        > > > And when done writing, I do :
        > > >
        > > > bw.close
        > > > fs.close
        > > >
        > > > Am I missing something?
        > > >
        > > > Thanks
        > > >
        > > > ThunderMusic
        > > >
        > > >
        > > >[/color][/color]
        >
        >
        >[/color]

        Comment

        • Cor Ligthert [MVP]

          #5
          Re: BinaryWriter and filesize limit. Is there any?

          thunderbyte,
          [color=blue]
          > In my app, I open a file using a FileStream then pass it to a
          > BinaryWriter. I then use the BinaryWriter instance to write to my file.
          > But
          > a problem arose : The file never gets bigger than 1kb. The code calls the
          > bw.write(TheVal ue), but nothing is written after 1kb. I'm I missing
          > something?[/color]

          Strange, if I use your code to write 15Kb of bytes I get 15Kb

          Cor


          Comment

          • Chris Dunaway

            #6
            Re: BinaryWriter and filesize limit. Is there any?

            Is it possible that when you write TheValueToWrite to the file, you are
            overwriting what is already in the file? Try opening the file stream
            in Append mode so that subsequent writes are appended to the end of the
            current file.

            Comment

            • ThunderMusic

              #7
              Re: BinaryWriter and filesize limit. Is there any?

              hi,
              Finaly, I found my problem was because while the app was running the
              application path was changing, so the file was not writing at the same place
              anymore. So when I was looking back to the file that was written (before the
              path change) it was 1k long (just a coincidence it was exactly this long),
              but the other one (written later in the app process, after the path change)
              was containing all the required data.

              I replaced the application path with a constant path and now it works fine.

              Sorry for bothering and thanks for all the help you provided

              ThunderMusic

              "ThunderMus ic" <NOdanylat@symp atico.caSPAMATA LL> a écrit dans le message de
              news:eVAcHeVmFH A.2976@TK2MSFTN GP10.phx.gbl...[color=blue]
              > Hi,
              > In my app, I open a file using a FileStream then pass it to a
              > BinaryWriter. I then use the BinaryWriter instance to write to my file.[/color]
              But[color=blue]
              > a problem arose : The file never gets bigger than 1kb. The code calls the
              > bw.write(TheVal ue), but nothing is written after 1kb. I'm I missing
              > something?
              >
              > Here's the way I create my FileStream and BinaryWriter :
              >
              > Filename = System.Environm ent.CurrentDire ctory() & "\msec.dat"
              > fs = System.IO.File. OpenWrite(Filen ame)
              > bw = New System.IO.Binar yWriter(fs)
              >
              > When I write I do:
              >
              > bw.write(TheVal ueToWrite)
              >
              > And when done writing, I do :
              >
              > bw.close
              > fs.close
              >
              > Am I missing something?
              >
              > Thanks
              >
              > ThunderMusic
              >
              >[/color]


              Comment

              Working...