Basic Stream operations

Source: Internet
Author: User

Basic Stream operations

// Convert the stream into a file 
Public static void StreamToFile (Stream stream, string filepath) {byte [] bytes = StreamToBytes (stream); FileStream fileStream = new FileStream (filepath, FileMode. create); fileStream. write (bytes, 0, bytes. length); fileStream. flush (); fileStream. close ();}
// Convert the stream into a byte arrayPublic static byte [] StreamToBytes (Stream stream) {MemoryStream memoryStream = new MemoryStream (); stream. CopyTo (memoryStream); return memoryStream. ToArray ();}
// Convert the stream to a Base64 string
Public static string StreamToString (Stream stream) {byte [] buffer = new byte [Stream. length]; stream. read (buffer, 0, (int) stream. length); string base64string = Convert. toBase64String (buffer); return base64string ;}
// Convert a Base64 string to a stream
Pubblic static Stream StringToStream (string str)
{
Byte [] bt = Convert. FromBase64String (str );
System. IO. MemoryStream stream = new System. IO. MemoryStream (bt );
}

..............

 

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.