首页 > 编程语言 >C# 读取文件流

C# 读取文件流

时间:2022-10-09 17:15:06浏览次数:39  
标签:文件 读取 C# source readBytes ex byte null

 1 /// <summary>
 2 /// 读取文件流
 3 /// </summary>
 4 /// <param name="filePath"></param>
 5 /// <returns></returns>
 6 public static byte[] ReadFileStream(string filePath)
 7 {
 8     Stream source = null;
 9     byte[] readBytes = null;
10     try
11     {
12         source = new FileStream(filePath, FileMode.Open, FileAccess.Read);
13         readBytes = new byte[source.Length];
14         source.Read(readBytes, 0, (int)source.Length);
15     }
16     catch (Exception ex)
17     {
18         throw ex;
19     }
20     finally
21     {
22         if (source != null)
23         {
24             source.Close();
25         }
26     }
27     return readBytes;
28 }

 

标签:文件,读取,C#,source,readBytes,ex,byte,null
From: https://www.cnblogs.com/smartnn/p/16772819.html

相关文章

  • pycharm 的vim配置
    "================================================================================================"=Extensions====================================="=====......
  • [转]OpenCV_Find Basis F-Matrix and computeCorrespondEpilines(获取一对图像的基础
    代码如下://BasisMatrixCalculate.cpp:定义控制台应用程序的入口点。//#include"stdafx.h"#include<iostream>#include<vector>#include<opencv2/core/c......
  • AtCoder Beginner Contest 272(A~E)
    Avoidsolve(intCase){intn;cin>>n;vector<int>a(n);for(auto&i:a)cin>>i;cout<<accumulate(all(a),0)<<nline;}Bconst......
  • Discovery of microscopic matter
    Inancienttimes,microscopicmattercouldnotbeobservedaccurately,sopeoplealwayslackedaccurateknowledgeofit.Rutherfordknockedonthedoortothes......
  • vue 前端导出PDF文件
    原理:通过对页面的截图进行生成PDF文件。PS:这里的截图指的是系统对页面的截图,不是你手动的截图,这里的截图进行可以长截图并且生成对应页数的PDF页码。  首先用npm引入......
  • leetcode-动态规划1-4
    目录leetcode-动态规划题目方法leetcode-动态规划题目1.斐波拉切数列2.爬楼梯3.买卖股票最佳时机(一次买卖)4.买卖股票最佳时机2(多次买卖)leetcode-动态规划题目方法五......
  • EasyCVR智能边缘网关设备提示报错该如何解决?
    EasyCVR视频融合平台部署轻快、功能灵活,在视频能力上,可提供视频直播、录像、回放、检索、云存储、级联、告警等功能。平台可支持多协议、多类型设备接入,包括国标GB28181、R......
  • Mysql 插入中文错误:Incorrect string value: '\xE7\xA8\x8B\xE5\xBA\x8F...' fo
     今天mysql遇到了一点问题。 首先我说一下,mysql安装的话默认编码方式是拉丁文。不是 UTF-8. 这个错误原因就是因为编码格式不一致造成的。  简单粗暴一点,重新建一个......
  • centos yum安装docker 步骤
    1、如果之前安装过docker需要进行卸载yumremovedocker2、安装必要的软件包,yum-util提供yum-config-manager功能yuminstall3、安装docker的devicemapper驱动依赖的软件包......
  • mac 下qt程序添加程序图标
    第一步桌面新建一个文件夹,命名为logo.iconset。将png图标(原图只能是.png文件)放进去。第二步:打开终端,cd到这个文件夹,依次执行下面的语句:sips-z1616logo.png--outicon_......