Reading Writing Bytes at a manageable rate
I have it on good authority that this is an excellent technique for transferring bytes from one file to another:
Dim fs As FileStream = New FileStream(path, FileMode.Open, FileAccess.Read)
Dim ws As FileStream = New FileStream(path, FileMode.Append, FileAccess.Write)
Dim Buffer(102400) As Byte
Dim BytesRead As Integer
Dim Chunksize As Integer = 102400
BytesRead = fs.Read(Buffer, 0, Chunksize)
While BytesRead > 0
ws.Write(Buffer, 0, BytesRead)
BytesRead = fs.Read(Buffer, 0, Chunksize)
End While
In particular, this is superior to saving the contents of a file in a string variable if there is any chance that the total memory required to store the file might exceed the limits of available RAM.
Labels: .NET 2.0, Appending, Coding Technique, File IO
1 Comments:
So, like many non-coders out there I look at your post here and mine eyes glosseth over.
Okay, not entirely a non-coder because I understand markup languages like HTML, CSS, and I can read some stuff (Mostly UNIX or Java based stuff, which isn't really your cup of tea I know). But check this out.
A bunch of students and hackers have gotten together to build some programs to assist kids (who may be put off by the complexity of coding languages today) in getting into coding.
One is called Scratch.
http://scratch.mit.edu/
This has an interesting way of writing code, by dragging and dropping code snippets into an outline that either interlock or don't based on what can/can't come next. Pretty neat.
The other project can be found here. It is based on the GPL language called Ruby.
http://hacketyhack.net/
I have played around with the latter and found it very well done.
I am going to learn that one I think so I can do rapid prototyping for usability projects.
Your boys may enjoy one or both of these.
Post a Comment
<< Home