Creating a Huge Dummy File in a Matter of Seconds in C#

后端 未结 5 461
梦如初夏
梦如初夏 2020-12-04 21:43

I want to create a huge dummy file say 1~2 GBs in matter of seconds. here is what I\'ve written in C# :

file.writeallbytes(\"filename\",new byte[a huge numbe         


        
5条回答
  •  粉色の甜心
    2020-12-04 22:11

    If you just need a FileStream, you could use FileStream.SetLength. That will get you a stream which is 2 GB long. Then you can write the final byte at an arbitrary position of your choice. But the contents will be undefined.

    If you're trying to actually create a file on the disk, yes, you'll need to actually write its contents. And yes, hard disks are going to be slow; something like a 1 GB/min write speed isn't totally ridiculous. Sorry -- that's physics!

提交回复
热议问题