FileStream

  • Thread starter Thread starter Pai
  • Start date Start date
P

Pai

Hello there,

I have been trying to read a document file into a byte array...

using the following code..., I wanted to do the same using Stream but
i am not sure how to make the same reference to a file.

FileInfo fi = new FileInfo("C:\\test.doc");
FileStream my_file = fi.OpenRead();

byte[] contents = new byte[my_file.Length];
my_file.Read (contents,0, (int)my_file.Length);

my_file.Close();

I am unable to go ahead.... lost :(

Please help

Kind Regards,
Srikanth Pai
 
Justin Rogers said:
I might be missing something, but Stream is simply the abstract base class.
FileStream inherits Stream and provides access to, well, file streams.
Using the base class really doesn't do you much good unless you are writing
methods that work generically with any type of stream. However, when
opening a stream, you still need knowledge of a non-abstract class such as
FileStream or NetworkStream. Stream is handy for users implementing a new
type of stream or when you are writing a library that is going to be called
by other developers.


--
Justin Rogers
DigiTec Web Consultants, LLC.

Pai said:
Hello there,

I have been trying to read a document file into a byte array...

using the following code..., I wanted to do the same using Stream but
i am not sure how to make the same reference to a file.

FileInfo fi = new FileInfo("C:\\test.doc");
FileStream my_file = fi.OpenRead();

byte[] contents = new byte[my_file.Length];
my_file.Read (contents,0, (int)my_file.Length);

my_file.Close();

Hello Justin,

I missed something here also....

the above code works well with a text file but does not work with a
word document file.

I need a byte array as a paramater to one of the functions....

how do i achieve this ....

Kind Regards,
Srikanth Pai.
 
Back
Top