Sets the current stream's position as the start of the stream
Stream. Seek (0, seekorigin.begin);
return bytes;
}
<summary>
Turn byte[] into a Stream
</summary>
Public Stream bytestostream (byte[] bytes)
{
Stream stream = new MemoryStream (bytes);
return stream;
}
/* - - - - - - - - - - - - - - - - - - - - - - - -
* Conversion between Stream and file
* - - - - - - - - - - - - - - - - - - - - - - - */
<summary>
Write Stream to File
</summary>
public void Streamtofile (Stream stream,string fileName)
{
Convert the Stream into byte[]
byte[] bytes = new Byte[stream. Length];
Stream. Read (bytes, 0, bytes. Length);
Sets the current stream's position as the start of the stream
Stream. Seek (0, seekorigin.begin);
Write byte[] to a file
FileStream fs = new FileStream (FileName, FileMode.Create);
BinaryWriter bw = new BinaryWriter (FS);
Bw. Write (bytes);
Bw. Close ();
Fs. Close ();
}
<summary>
Read Stream from File
</summary>
Public Stream Filetostream (string fileName)
{
Open File
FileStream FileStream = new FileStream (FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
Read byte[of file]
byte[] bytes = new Byte[filestream.length];
FileStream.Read (bytes, 0, bytes. Length);
Filestream.close ();
Convert byte[] into Stream
Stream stream = new MemoryStream (bytes);
return stream;
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.