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, ...
随机推荐
- json格式字符串与java.util.Map的互转(借助于jackson.jar)
package com.test.javaAPI.json; /** * json工具类 * * @author Wei * @time 2016年10月2日 下午4:25:25 */ public ...
- day4作业
作业内容:计算器 #!/usr/bin/env python # -*- coding:utf-8 -*- import re,time #加减字符处理函数 def handle_symbol(cal ...
- 关于QuartusII中的文件加密
有时候我们要把工程交接给别人,但是又不希望对方看到里面的东西.在网上查找了几位大牛的博客进行整合 来自coyoo博客 http://bbs.ednchina.com/BLOG_ARTICLE_2482 ...
- Protel对话窗字体显示不完全问题解决办法(PCB)
点击protel99左上角的大箭头,点击preferences ,在对话框中把use client system fonts for all dialogs 复选框去掉,就可以了.
- cocos2dx进阶学习之CCDirector
继承关系 CCDirecotor -> CCObject, TypeInfo 处理主窗口消息,管理何时.何种方式执行场景. 经常被翻译成导演,负责管理整个游戏的进程推动和周边支持. 成员 inl ...
- 基于visual Studio2013解决C语言竞赛题之0409 100以内素数
题目 解决代码及点评 在已经知道素数是怎么判断的基础上,增加循环,可以判断出100以内的素数 /******************************************* ...
- Sicily-1006
一. 题意 这道题就是考排列组合吧,再来就是比较一下字符的下标算一下两个ranking的距离.然后我总结了一个排列和一个组合的实现方法,这道题直接用的是stl 里面的next_permutation ...
- Python模拟登陆
模拟人人登陆 #encoding=utf-8 import urllib2 import urllib import cookielib def renrenBrower(url,user,passw ...
- C++之字符串分割函数split
c++之字符串分割: /* *c++之字符串分割: */ #include <iostream> #include <string> #include <vector&g ...
- PHP - 继承 - 子类使用父类方法
<?php class ShopProduct { private $FirstName; private $LastName; private $Title; private $Price; ...