zoukankan      html  css  js  c++  java
  • filestream read方法 循环读取固定文件

    1、循环读取啊,byte[]可以定义为1024或者2049等等,不要超过int的maxvalue就可以。
    然后取出来操作完再去取。

     1  FileStream stream = new FileStream(path);
     2  byte[] writeData = new byte[8192];
     3   // Use the ReadAllBytesFromStream to read the stream.
     4   while (true)
     5   {
     6        int size = stream.Read(writeData, 0, writeData.Length);
     7        if (size > 0)
     8        {
     9             //你操作数据的代码
    10       }
    11        else
    12        {
    13             break;
    14        }
    15   }
    16   stream.Close();

    2、C# filestream.Read用在while循环有啥用?
    FileStream fs = File.OpenRead("C:\test.txt");
    byte[] arr = new byte[100];
    while (filestream.Read(arr, 0, arr.Length)>0)
    {
    Console.WriteLine(data.GetString(arr));
    }
    回答:循环读取文件,每次只读100个字节

    string str = "C:\test.txt";
                            if (!File.Exists(str))     ///检测文件是否存在
                               {
                                           MessageBox.Show("文件不存在,请查看客户端是否已经上传数据!");
                               }
                           else
                              {   
                                     FileStream fop = File.OpenRead(str);
                                     byte[] arr = new byte[1000];
                                     while (fop.Read(arr, 0, arr.Length) > 0)    ///这个循环会将文件所有的内容都读取出来
                                      {
                                      ClientSocket[1].Send(arr, 0, arr.Length,0);
                                      }
                                     fop.Close();
                                 }
  • 相关阅读:
    LINUX 系统性能检测工具vmstat
    ebs 初始化登陆
    oracle 以SYSDBA远程连接数据库
    ORACLE hint
    ORACLE CACHE BUFFER CHAINS原理
    oracle 当月日历的sql
    oracle to_char处理日期
    EBS 抓trace 文件
    oracle 执行计划的获取方法
    linux ln用法
  • 原文地址:https://www.cnblogs.com/frustrate2/p/3680471.html
Copyright © 2011-2022 走看看