Hello nano2k,
use this one
using (FileStream stream = new FileStream(path , FileMode.Create , FileAccess.Writ e,
FileShare.Read) )
{
stream.Write(by tes, 0, bytes.Length);
}
u can do in blocks, writing to file several times
---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog:
http://spaces.live.com/laflour
"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
nOn 31 Aug, 13:09, marss <marss...@gmail .comwrote:
n>
>On 31 , 12:59, nano2k <adrian.rot...@ ikonsoft.rowrot e:
>>Hi
For some purposes, I need to create a new binary file and to
allocate
a fixed length for that file on the disk.
I need something like File.Create(str ing fileName, long
initialSizeIn Bytes).
Is there a framework/system method to do that or should I create the
file and then fill it until the size is reached?
Thanks
System.IO.File .WriteAllBytes( "file.txt", new byte[100]);
Regards,
Mykolahttp://marss.co.ua
nHi Mykola
nThanks for your response.
nI'm using .NET Framework 1.1, so this method you suggested is not
navailable in my case.
nThe files I will create are far larger than you suggested in your
npost. May be hundreds of megs, or even few gigs.
nWhat you suggest is that I should create a file, than write the
namount
nof bytes I need. Writing in one shot is not ok. It's not my desire to
nallocate a huge buffer just to tranfer it to a file.
nI'd rather write to file successively a reasonable sized buffer until
nthe desired size is reached.
nThis is my approach at the moment, but I thought that there should be
na another, more optimum, way to do it.