Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to load a file into memory stream

Tags:

.net

vb.net

I have a filename pointing to a text file, including its path, as a string. Now I'd like to load this .csv file into memory stream. How should I do that?

For example, I have this:

Dim filename as string="C:\Users\Desktop\abc.csv" 
like image 388
Ram Avatar asked Jun 02 '11 11:06

Ram


People also ask

How do I save files to my memory stream?

One solution to that is to create the MemoryStream from the byte array - the following code assumes you won't then write to that stream. MemoryStream ms = new MemoryStream(bytes, writable: false); My research (below) shows that the internal buffer is the same byte array as you pass it, so it should save memory.

How do you use memory as a stream object?

This code shows how to use MemoryStream class and its member to read data in memory stream, which can be used to save it from there. int count; //GetByteData function to get Byte data like if you fetch Image column data from sqlserver or somewhere. byte[] byteArray = getByteData();

How does memory stream work?

MemoryStream encapsulates data stored as an unsigned byte array. The encapsulated data is directly accessible in memory. Memory streams can reduce the need for temporary buffers and files in an application. The current position of a stream is the position at which the next read or write operation takes place.

How do I open memory stream?

MemoryStream creates streams that have memory as a backing store instead of a disk or a network connection. This can be useful in eliminating the need to write temporary files to disk or to store binary blob information in a database. To open or read file we use FileStream.


1 Answers

Dim stream As New MemoryStream(File.ReadAllBytes(filename)) 
like image 151
Centro Avatar answered Sep 20 '22 02:09

Centro