C# - MemoryStream
代码:
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的更多相关文章
- Stream转MemoryStream解决Stream.Length报错此流不支持查找操作
1.StreamToMemoryStream MemoryStream StreamToMemoryStream(Stream instream) { MemoryStream outstream = ...
- C#--几个数据流Stream;StreamReader;StreamWriter;MemoryStream;BufferStream;
命名空间:System.IO; Stream: 各种流的基类,不能时行查找操作,Position属性不能修改.读取时不Position不会自动移动, HttpWebRequest webreq = ( ...
- The file 'MemoryStream' is corrupted! 的解决办法
The file 'MemoryStream' is corrupted! Remove it and launch unity again! [Position > ] 有时候我们会遇到这个报 ...
- [C#]MemoryStream.Dispose之后,为什么仍可以ToArray()?
目录 概述 MemoryStream分析 总结 概述 事件起因,一哥们在群里面贴出了类似下面这样的一段代码: class Program { static void Main(string[] arg ...
- MemoryStream 的GetBuffer() 和 ToArray()的区别
GetBuffer(): Note that the buffer contains allocated bytes which might be unused. For example, if th ...
- 【Delphi】从内存(MemoryStream)使用WMP(WindowsMediaPlayer)控件播放视频音频(Play Video with WMP from MemoryStream)
关键字: MemoryStream.WMP.WindowsMediaPlayer.Play .Load. Delphi.C++.C#.ActiveX控件 作 者: CaiBirdy 问 题:正常使 ...
- MemoryStream类
转自:http://www.cnblogs.com/kissdodog/archive/2013/01/20/2868864.html MemoryStream 是一个特例,MemoryStream中 ...
- WEB API 用MemoryStream流做下载功能
刚开始把MemoryStream 放在 var streamResult = new MemoryStream(); HttpResponseMessage response = new HttpRe ...
- 字符串string和内存流MemoryStream及比特数组byte[]互转
原文:字符串string和内存流MemoryStream及比特数组byte[]互转 字符串string和内存流MemoryStream及比特数组byte[]互转比较 定义string变量为str, ...
随机推荐
- 迪杰斯特拉算法c语言实现
/*http://1wangxiaobo@163.com 数据结构C语言版 迪杰斯特拉算法 P189 http://1wangxiaobo@163.com 编译环境:Dev-C++ 4.9.9.2 ...
- mac下 配置 Apache Php Mysql
参考 http://www.guomii.com/posts/30136 参考 http://forums.mysql.com/read.php?11,600754,600754 MacOS 10.8 ...
- Windows Phone 8初学者开发—第3部分:编写第一个Windows Phone 8应用程序
原文 Windows Phone 8初学者开发—第3部分:编写第一个Windows Phone 8应用程序 原文地址: http://channel9.msdn.com/Series/Windows- ...
- python爬虫实战1
转载于:http://blog.csdn.net/dongnanyanhai/article/details/5552431 首先推荐一个网站:中医世家,这个网站上有很多关于中医的资料,光是提供的中医 ...
- notify()、notifyAll()和wait()
看到一道面试题,写一个多线程程序,交替输出1.2.1.2…… 先写下程序: /** * Created by Andrew on 2015/10/28. */ public class OutputT ...
- android linearlayout imageview置顶摆放
在练习android时,想在Linearlayout内放一图片,使其图片置顶,预期效果是这样的: 但xml代码imageview写成这样后, <ImageView android:layout_ ...
- Spreadsheets
很水的一道题,提醒自己要认真,做的头都快晕了.考虑26的特殊情况. D - Spreadsheets Time Limit:10000MS Memory Limit:65536KB 6 ...
- centos安装vim7.4
转载于:http://www.cnblogs.com/nhlinkin/p/3545509.html 系统版本centos6.4; root权限 su - root 卸载 $ rpm - ...
- Ubuntu15.04上为火狐浏览器安装Adobe Flash Player插件
前言:最新版的ubuntu好像没有flashplayer,而且更新源也无法更新成功,找些资料终于发现 这个需要自己手动配置.由于flashplayer无法安装,导致视频,百度上传等功能都无法使用: 安 ...
- [置顶] PHP调用move_uploaded_file()提示 failed to open stream: Permission denied(Linxux环境,以Ubuntu12.04为例)
在使用PHP上传文件之后,我们有时候还需要移动到特定的文件夹,这时候就要调用move_uploaded_file()函数,可是会出现如下错误: Warning: move_uploaded_file( ...