PC Review


Reply
Thread Tools Rate Thread

BinaryWriter and filesize limit. Is there any?

 
 
ThunderMusic
Guest
Posts: n/a
 
      5th Aug 2005
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(TheValue), but nothing is written after 1kb. I'm I missing
something?

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

Filename = System.Environment.CurrentDirectory() & "\msec.dat"
fs = System.IO.File.OpenWrite(Filename)
bw = New System.IO.BinaryWriter(fs)

When I write I do:

bw.write(TheValueToWrite)

And when done writing, I do :

bw.close
fs.close

Am I missing something?

Thanks

ThunderMusic


 
Reply With Quote
 
 
 
 
=?Utf-8?B?U2NvdHQgU3dpZ2FydA==?=
Guest
Posts: n/a
 
      5th Aug 2005
What's "TheValueToWrite" defined as? Are you just writing one value?

Scott Swigart
VB - MVP

"ThunderMusic" wrote:

> 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(TheValue), but nothing is written after 1kb. I'm I missing
> something?
>
> Here's the way I create my FileStream and BinaryWriter :
>
> Filename = System.Environment.CurrentDirectory() & "\msec.dat"
> fs = System.IO.File.OpenWrite(Filename)
> bw = New System.IO.BinaryWriter(fs)
>
> When I write I do:
>
> bw.write(TheValueToWrite)
>
> And when done writing, I do :
>
> bw.close
> fs.close
>
> Am I missing something?
>
> Thanks
>
> ThunderMusic
>
>
>

 
Reply With Quote
 
 
 
 
ThunderMusic
Guest
Posts: n/a
 
      5th Aug 2005
hi,
no, I'm not writing just 1 value... the "TheValueToWrite" 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" <(E-Mail Removed)> a écrit dans le message de
news:(E-Mail Removed)...
> What's "TheValueToWrite" defined as? Are you just writing one value?
>
> Scott Swigart
> VB - MVP
>
> "ThunderMusic" wrote:
>
> > 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(TheValue), but nothing is written after 1kb. I'm I missing
> > something?
> >
> > Here's the way I create my FileStream and BinaryWriter :
> >
> > Filename = System.Environment.CurrentDirectory() & "\msec.dat"
> > fs = System.IO.File.OpenWrite(Filename)
> > bw = New System.IO.BinaryWriter(fs)
> >
> > When I write I do:
> >
> > bw.write(TheValueToWrite)
> >
> > And when done writing, I do :
> >
> > bw.close
> > fs.close
> >
> > Am I missing something?
> >
> > Thanks
> >
> > ThunderMusic
> >
> >
> >



 
Reply With Quote
 
=?Utf-8?B?U2NvdHQgU3dpZ2FydA==?=
Guest
Posts: n/a
 
      5th Aug 2005
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 = "0123456789012345678901234567890123456789"
Dim filename As String = System.Environment.CurrentDirectory() &
"\msec.dat"
Dim fs As Stream = File.Open(filename, FileMode.Create,
FileAccess.Write)
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


"ThunderMusic" wrote:

> hi,
> no, I'm not writing just 1 value... the "TheValueToWrite" 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" <(E-Mail Removed)> a écrit dans le message de
> news:(E-Mail Removed)...
> > What's "TheValueToWrite" defined as? Are you just writing one value?
> >
> > Scott Swigart
> > VB - MVP
> >
> > "ThunderMusic" wrote:
> >
> > > 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(TheValue), but nothing is written after 1kb. I'm I missing
> > > something?
> > >
> > > Here's the way I create my FileStream and BinaryWriter :
> > >
> > > Filename = System.Environment.CurrentDirectory() & "\msec.dat"
> > > fs = System.IO.File.OpenWrite(Filename)
> > > bw = New System.IO.BinaryWriter(fs)
> > >
> > > When I write I do:
> > >
> > > bw.write(TheValueToWrite)
> > >
> > > And when done writing, I do :
> > >
> > > bw.close
> > > fs.close
> > >
> > > Am I missing something?
> > >
> > > Thanks
> > >
> > > ThunderMusic
> > >
> > >
> > >

>
>
>

 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      5th Aug 2005
thunderbyte,

> 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(TheValue), but nothing is written after 1kb. I'm I missing
> something?


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

Cor


 
Reply With Quote
 
Chris Dunaway
Guest
Posts: n/a
 
      5th Aug 2005
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.

 
Reply With Quote
 
ThunderMusic
Guest
Posts: n/a
 
      7th Aug 2005
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

"ThunderMusic" <(E-Mail Removed)> a écrit dans le message de
news:(E-Mail Removed)...
> 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(TheValue), but nothing is written after 1kb. I'm I missing
> something?
>
> Here's the way I create my FileStream and BinaryWriter :
>
> Filename = System.Environment.CurrentDirectory() & "\msec.dat"
> fs = System.IO.File.OpenWrite(Filename)
> bw = New System.IO.BinaryWriter(fs)
>
> When I write I do:
>
> bw.write(TheValueToWrite)
>
> And when done writing, I do :
>
> bw.close
> fs.close
>
> Am I missing something?
>
> Thanks
>
> ThunderMusic
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BinaryWriter and filesize limit. Is there any? ThunderMusic Microsoft VB .NET 6 7th Aug 2005 06:15 AM
IDisposable not implemented in BinaryReader and BinaryWriter? Brane Brodnik Microsoft Dot NET Compact Framework 1 9th Mar 2004 11:02 PM
BinaryReader and BinaryWriter and Endianess Paul Selormey Microsoft Dot NET Framework 7 12th Feb 2004 09:08 AM
BinaryWriter and string data type John Aldrin Microsoft C# .NET 6 1st Jan 2004 06:33 PM
BinaryWriter.Seek() vs BinaryWriter.BaseStream.Seek() Daniel Goldman Microsoft Dot NET Framework 6 30th Aug 2003 08:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:40 AM.