The Developer Page

Coding Tutorials and More!

Using File Streams to Write Any Size File : Introduction


A few days ago, I set out to create a program that would simply copy a file directory from location to another. I built the program, the logic was simple enough, and had it finished in a few hours. Low and behold it worked wonders on my test files. I was amazed at how easy everything was, and then I tried to put it to its actual task, copying 1GB+ files from a  backup directory at work, to an archived directory over network (still at work), so that our content wouldn’t be overwritten whenever it was backed up.

I smiled, as my program hung after the very first file was copied. It was just too good to be true I thought, scrambling through my brain for a solution to this strange problem. The program worked incredibly well on the files I had tested. They were much smaller of course, but why would that be a prob…. my thoughts halted as a solution formed.

After a moment, I came to the logical conclusion that it must have something to do with a buffer. this meant that the error was somewhere in the actual copy method. However, I had intended this to be a very quick and easy program to build, and as such I had used Microsoft’s very own FileInfo.copyTo() method to copy the files.

I quickly placed a few writeLines to test where the file hung and tried it again. Sure enough, the file hung exactly on the line containing this method. I smiled, remembering one of my favorite quotes “nothing is ever easy”.

However, I was determined to finish my program, and to make it work well. I first searched for a way to change the buffer on the FileInfo.copyTo() method. Unfortunately, I couldn’t find any information on it. Thus began my journey to solve my problem with the great fileStream. If my problem really was the buffer, then I needed a way to change the buffer in case files were too large to copy anyway. Filestreams have the amazing ability to do just that.

1 2 3 Next

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: