代码:

 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; //
using System.IO; namespace APPMemoryStream
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
//将空间中的内容转换成二进制流
byte[] data = Encoding.Unicode.GetBytes(this.richTextBox1.Rtf); //将二进制文件存储到内存流
MemoryStream stream = new MemoryStream(data); //设置文件每块发送的长度
int sendlen = ; //获取整个文件的大小
long sunlen = (stream.Length); //设置文件发送的起始位置
int offset = ; //分块获取信息
while (sunlen > )
{
sendlen = ; //如果文件没有读取完毕
if (sunlen <= sendlen)
{
sendlen = Convert.ToInt32(sunlen);
} //创建一个1024大小的二进制流
byte[] msgdate = new byte[sendlen]; //将字节块读取到内存流,以便于进行其他操作
stream.Read(msgdate, offset, sendlen); //记录下一块的起始位置
sunlen = sunlen - sendlen;
}
}
}
}

C# - MemoryStream的更多相关文章

  1. Stream转MemoryStream解决Stream.Length报错此流不支持查找操作

    1.StreamToMemoryStream MemoryStream StreamToMemoryStream(Stream instream) { MemoryStream outstream = ...

  2. C#--几个数据流Stream;StreamReader;StreamWriter;MemoryStream;BufferStream;

    命名空间:System.IO; Stream: 各种流的基类,不能时行查找操作,Position属性不能修改.读取时不Position不会自动移动, HttpWebRequest webreq = ( ...

  3. The file 'MemoryStream' is corrupted! 的解决办法

    The file 'MemoryStream' is corrupted! Remove it and launch unity again! [Position > ] 有时候我们会遇到这个报 ...

  4. [C#]MemoryStream.Dispose之后,为什么仍可以ToArray()?

    目录 概述 MemoryStream分析 总结 概述 事件起因,一哥们在群里面贴出了类似下面这样的一段代码: class Program { static void Main(string[] arg ...

  5. MemoryStream 的GetBuffer() 和 ToArray()的区别

    GetBuffer(): Note that the buffer contains allocated bytes which might be unused. For example, if th ...

  6. 【Delphi】从内存(MemoryStream)使用WMP(WindowsMediaPlayer)控件播放视频音频(Play Video with WMP from MemoryStream)

    关键字: MemoryStream.WMP.WindowsMediaPlayer.Play .Load. Delphi.C++.C#.ActiveX控件 作  者: CaiBirdy 问  题:正常使 ...

  7. MemoryStream类

    转自:http://www.cnblogs.com/kissdodog/archive/2013/01/20/2868864.html MemoryStream 是一个特例,MemoryStream中 ...

  8. WEB API 用MemoryStream流做下载功能

    刚开始把MemoryStream 放在 var streamResult = new MemoryStream(); HttpResponseMessage response = new HttpRe ...

  9. 字符串string和内存流MemoryStream及比特数组byte[]互转

    原文:字符串string和内存流MemoryStream及比特数组byte[]互转   字符串string和内存流MemoryStream及比特数组byte[]互转比较 定义string变量为str, ...

随机推荐

  1. python2.5_1.5_通过指定的端口和协议找到服务名

    代码如下: # -*- coding: utf-8 -*- import socket def find_service_name(): protocolname = 'tcp' for port i ...

  2. 2013 南京邀请赛 C count the carries

    /** 大意: 给定区间(a,b), 将其转化为二进制 计算从a+(a+1)+(a+2)....+(a+b-1),一共有多少次进位 思路: 将(a,b)区间内的数,转化为二进制后,看其每一位一共有多少 ...

  3. border-radius.htc为ie6-8实现圆角

    ~~圆角是比较常用的css3属性,但是ie6-8并不支持圆角,可用border-radius.htc  html组件实现圆角, border-radius.htc内部应用vml进行了重绘 border ...

  4. mysql基础(mysql数据库导入到处) 很基础很实用

    一.MYSQL的命令行模式的设置:桌面->我的电脑->属性->环境变量->新建->PATH=“:path\mysql\bin;”其中path为MYSQL的安装路径.二.简 ...

  5. WebHdfs

    https://github.com/ihrwein/webhdfs https://tiborbenke.blogs.balabit.com/2013/11/the-syslog-ng-in-the ...

  6. IT第十天 - String和StringBuffer的比较、编程设计技巧整理、本周总结 ★★★

    IT第十天 上午 String 1.String在进行多次的+扩展时,会严重的降低处理效率,因为String长度是不可变的,在进行+运算改变字符串时,会自动创建很多临时字符串,并不是在原字符串上追加, ...

  7. 搭建你的持续集成server - CruiseControl step by step(1)

    CruiseControl是CIserver的老者,诞生已是多年,在很多方面,CruiseControlserver已经成为持续集成实践的同义词.而如今,CruiseControl已发展成为一个家族式 ...

  8. Codeforces Round #262 (Div. 2) 460C. Present(二分)

    题目链接:http://codeforces.com/problemset/problem/460/C C. Present time limit per test 2 seconds memory ...

  9. Windows Time服务无法启动 错误5拒绝访问

    接着上次写的文章 XP和Win7设置系统自动同步系统时间方法 本文就把故障出现的过程和解决方法一共写下来,希望大家可以看到本文在解决此项服务的思路.大家以后出现类似的问题和问题可以一样使用此类方法解决 ...

  10. MVC自定义AuthorizeAttribute实现权限管理

    [转]MVC自定义AuthorizeAttribute实现权限管理 原文载自:小飞的DD http://www.cnblogs.com/feiDD/articles/2844447.html 网站的权 ...