Stream Operation Z

Source: Internet
Author: User

The common and commonly used stream has

File Stream (FileStream),

Memory Stream (MemoryStream),

Compressed stream (GZipStream),

Encrypted stream (CryptoStream),

Network flow (NetworkStream);

1. File stream (read file stream-output file stream) FileStream

using (streamstreamwrite=new FileStream (@ "D:\BaiduYunDownload\45.avi", FileMode.OpenOrCreate))
{
using (Stream streamread = new FileStream (@ "D:\BaiduYunDownload\xiawu3.avi", FileMode.Open))
{
Byte[] Ss=new byte[1024*1024*4];
int Len;
while (len = Streamread. Read (SS, 0, SS. Length)) > 0)
{
Streamwrite. Write (ss, 0, Len);
Thread.Sleep (1000);
}
}
}

2. memory Stream (MemoryStream)

String strtxt= "DASDFDSFSD";
byte[] Bytetxt = Encoding.UTF8.GetBytes (strtxt);
Stream Memstream = new MemoryStream ();
Memstream. Write (bytetxt, 0, Bytetxt. Length);

3. Compressed stream (GZipStream),

Compression:

string s = "DFDFDF";
using (FileStream FileStream = File.openwrite (@ "C:\2.txt"))
{
using (GZipStream ZIPstream = new GZipStream (FileStream, compressionmode.compress))
{
byte[] bytes = Encoding.UTF8.GetBytes (s);
ZIPstream. Write (bytes, 0, bytes. Length);
}
}

Extract:

using (FileStream FileStream = File.openread (@ "C:\2.txt"))
{
using (GZipStream ZIPstream = new GZipStream (FileStream, compressionmode.decompress))
{
using (FileStream filestreamwrite = new FileStream (@ "C:\3.txt", FileMode.OpenOrCreate))
{
byte[] bytes = new byte[1024 * 1024 * 4];
int length;
while (length = ZIPstream. Read (bytes, 0, bytes. Length)) > 0)
{
Filestreamwrite. Write (bytes, 0, length);
}
}
}
}

Stream Operation Z

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.