zoukankan      html  css  js  c++  java
  • C#

    代码:

     1 using System;
     2 using System.Collections.Generic;
     3 using System.ComponentModel;
     4 using System.Data;
     5 using System.Drawing;
     6 using System.Linq;
     7 using System.Text;
     8 using System.Windows.Forms;
     9 
    10 //
    11 using System.IO;
    12 
    13 namespace APPMemoryStream
    14 {
    15     public partial class Form1 : Form
    16     {
    17         public Form1()
    18         {
    19             InitializeComponent();
    20         }
    21 
    22         private void Form1_Load(object sender, EventArgs e)
    23         {
    24 
    25         }
    26 
    27         private void button1_Click(object sender, EventArgs e)
    28         {
    29             //将空间中的内容转换成二进制流
    30             byte[] data = Encoding.Unicode.GetBytes(this.richTextBox1.Rtf);
    31 
    32             //将二进制文件存储到内存流
    33             MemoryStream stream = new MemoryStream(data);
    34 
    35             //设置文件每块发送的长度
    36             int sendlen = 1024;
    37 
    38             //获取整个文件的大小
    39             long sunlen = (stream.Length);
    40 
    41             //设置文件发送的起始位置
    42             int offset = 0;
    43 
    44             //分块获取信息
    45             while (sunlen > 0)
    46             {
    47                 sendlen = 1024;
    48 
    49                 //如果文件没有读取完毕
    50                 if (sunlen <= sendlen)
    51                 {
    52                     sendlen = Convert.ToInt32(sunlen);
    53                 }
    54 
    55                 //创建一个1024大小的二进制流
    56                 byte[] msgdate = new byte[sendlen];
    57 
    58                 //将字节块读取到内存流,以便于进行其他操作
    59                 stream.Read(msgdate, offset, sendlen);
    60 
    61                 //记录下一块的起始位置
    62                 sunlen = sunlen - sendlen;
    63             }
    64         }
    65     }
    66 }
  • 相关阅读:
    mysql自定义函数
    MYSQL常见运算符和函数
    PHP魔术方法和魔术变量总结
    魔术常量(Magic constants)
    常量和静态变量会先载入内存后在进行执行php代码
    php IP转换整形(ip2long)
    面试题1
    Java 通过 BufferReader 实现 文件 写入读取 示例
    UVA 2039 Pets(网络流)
    [置顶] Android框架攻击之Fragment注入
  • 原文地址:https://www.cnblogs.com/KTblog/p/4515571.html
Copyright © 2011-2022 走看看