Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to convert System.Byte[] in System.IO.Stream?

Tags:

c#

stream

I can't convert byte to stream. Is there an easy way to do that?

Stream stream;
stream = (Stream) vByte; //something is going wrong in this part. 
//vByte is a byte variable
like image 946
Daniel Oliveira Avatar asked May 24 '13 13:05

Daniel Oliveira


People also ask

How do you convert a byte array into a string?

There are two ways to convert byte array to String: By using String class constructor. By using UTF-8 encoding.

What is used to convert stream of bytes to object?

Deserializing (converting byte array into Object)

Is a byte array a stream?

Streams are commonly written to byte arrays. The byte array is the preferred way to reference binary data in . NET. It can be used to data like the contents of a file or the pixels that make up the bitmap for an image.

How do I convert files to stream?

First create FileStream to open a file for reading. Then call FileStream. Read in a loop until the whole file is read. Finally close the stream.


1 Answers

You need to instantiate a MemoryStream object with the byte[]:

    MemoryStream stream = new MemoryStream(vByte);
like image 100
Evan L Avatar answered Oct 12 '22 02:10

Evan L