views:

461

answers:

2

After getting the file name I create a new filestream and load all the bytes from the FileStream into a byte array, now I need to get certain bytes and store them in fields like the second 4 bytes are the time the file was created. When storing these in the variables should I store them as bytes or as string/integers/etc.

Or have I done it completely wrong?

EDIT:Should I be doing this way instead of a filestream?

Dim data() as Byte = File.ReadAllBytes(path1)
+1  A: 

Try reading the stream using the Read method(s), instead of copying the entire file into memory, if all you're doing is sequential reading. Then while reading, store a date/time as a DateTime value, etc.

Sander Rijken
I am going to eventually write to the file. Does that make a difference?
Jonathan
A: 

Using File.ReadAllBytes is a perfectly fine way of doing what you want to do. This is example of an aggregate component which uses several factored types under the covers to accomplish a common task. If you were to manually open a StreamReader and read the contents of the file you would be re-coding the implementation of File.ReadAllBytes almost exactly.

An aggregate component is simply a type that provides a very high-level API over several lower-level types. The File type is a perfect example of an aggregate component since it has many methods that allow you to do common tasks simply and without having to create and use the underlying types (or "factored types" like StreamReader).

I think what you have now is just fine - it is simple and straightforward (which is the entire reason aggregate components exist in the first place).

Andrew Hare