代码:

 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. myEclipse快捷键及其常用设置

    快捷键:    查找替换:ctrl + f    复制行: ctrl + alt + down    删除行: ctrl + d    插入行: shift + enter, ctrl + shift ...

  2. js方法中的this

    比如有个function: function ServiceMy(services) { //存放this,用于调试用 var tmp_this = this; this.services = []; ...

  3. 无法将类型“ASP.login_aspx”转换为“System.Web.UI.WebControls.Login”

    今天碰上了一个很傻的问题,起码我认为是这样. 项目中首页名是:Login.aspx,编译.运行都没有出现问题. 于是打包发布网站,各项内容都配置好后,问题出现了.一运行首页面就出现下面这个错误: 编译 ...

  4. 引用 IP电话的原理结构及其关键技术

    引用 茫然 的 两种将字符串转换成浮点数的方法 方法一: char szString[] = "-2876.99812376443"; double db1; db1 = atof ...

  5. Vim中如何全选并复制?

    全部删除:按esc后,然后dG全部复制:按esc后,然后ggyG 全选高亮显示:按esc后,然后ggvG(这个好像有点问题)或者ggVG正确 vim如何与剪贴板交互(将vim的内容复制出来) 习惯了在 ...

  6. 1297 - Largest Box(三分)

    1297 - Largest Box   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB In t ...

  7. window.open 使用方法总结

    [1.最基本的弹出窗口代码] <SCRIPT LANGUAGE="javascript">  <!--  window.open ('test.html')  - ...

  8. c++隐藏实例

    隐藏:是指派生类的函数屏蔽了与其同名的基类函数,规则如下:(1)如果派生类的函数与基类的函数同名,但是参数不同.此时,不论有无virtual关键字,基类的函数将被隐藏(注意别与重载混淆). 很简单略去 ...

  9. [Swust OJ 217]--Factor(数论,类素数表)

    题目链接:http://acm.swust.edu.cn/problem/0217/ Time limit(ms): 2000 Memory limit(kb): 65535    Descripti ...

  10. ZOJ 2972 Hurdles of 110m 【DP 背包】

    一共有N段过程,每段过程里可以选择 快速跑. 匀速跑 和 慢速跑 对于快速跑会消耗F1 的能量, 慢速跑会集聚F2的能量 选手一开始有M的能量,即能量上限 求通过全程的最短时间 定义DP[i][j] ...