473,387 Members | 3,684 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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(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
Nov 21 '05 #1
6 1533
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

Nov 21 '05 #2
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" <sc***@swigartconsulting.com> a écrit dans le message de
news:26**********************************@microsof t.com...
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

Nov 21 '05 #3
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" <sc***@swigartconsulting.com> a écrit dans le message de
news:26**********************************@microsof t.com...
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


Nov 21 '05 #4
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
Nov 21 '05 #5
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.

Nov 21 '05 #6
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" <NO*******@sympatico.caSPAMATALL> a écrit dans le message de
news:eV**************@TK2MSFTNGP10.phx.gbl...
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

Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Michel Rosien | last post by:
Hello All, I am trying to read data from a textfile using std::ifstream. The problem is that I have a very huge text file, approximately 4.8 GB. When I use this file, the program I wrote refuses...
3
by: Mark Miller | last post by:
I have a char array and when I write it to a file using BinaryWriter the position of the pointer is the size of the array + 1. For example: writing char leaves the pointer at position 26 after...
4
by: Ken | last post by:
I would like to measure the fileSize of the image (without uploading it - php). I use: var size_pic = document.getElementById('num1').childNodes.fileSize; alert("size = " + size_pic); which...
6
by: ThunderMusic | last post by:
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....
35
by: deko | last post by:
Do I get more scalability if I split my database? The way I calculate things now, I'll be lucky to get 100,000 records in my Access 2003 mdb. Here some math: Max mdb/mde size = 2000 x 1024 =...
17
by: Filip Strugar | last post by:
Considering that the BinaryWriter/BinaryReader object closes the underlaying stream upon being gc collected, is the following code correct, and if it is what is the reason preventing BinaryWriter...
3
by: Eugene | last post by:
I'm trying to write a class which uses BinaryWriter as its base but allows for queuing of write requests Public Class QueuedBinaryWriter Inherits BinaryWriter I override all the Write methods...
0
by: Thomas Gurath | last post by:
I have some code that reads a file from disk and inserts it into the http response. When the user clicks the file's title linkbutton, the File Download prompt appears twice if they select Open...
8
by: VB Programmer | last post by:
I am using a FileUpload control (ASP.NET 2.0). How do I check the length of the file in bytes BEFORE I let them upload it? I believe my code checks now AFTER... If...
3
by: =?Utf-8?B?ZnVuZG9vX2ty?= | last post by:
Check the following code ///Buffer to store the data byte data = new byte; ///Create a memory stream from the buffer MemoryStream memStream = new MemoryStream(data); ///Binary writer...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.