首頁>Club>
6
回覆列表
  • 1 # 使用者9937787127551

    常見並常用的stream一共有

    檔案流(FileStream),

    記憶體流(MemoryStream),

    壓縮流(GZipStream),

    加密流(CrypToStream),

    網路流(NetworkStream);

    1.檔案流(讀取檔案流-輸出檔案流)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. 記憶體流(MemoryStream)

    string strtxt="dasdfdsfsd";

    byte[] bytetxt = Encoding.UTF8.GetBytes(strtxt);

    Stream memstream = new MemoryStream();

    memstream.Write(bytetxt, 0, bytetxt.Length);

    3.壓縮流(GZipStream),

    壓縮:

    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);

    }

    }

    解壓:

    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);

    }

    }

    }

    }

  • 中秋節和大豐收的關聯?
  • 姐姐不適合長住孃家,小舅子小姨子常去結婚的姐姐家蹭飯呢?