C# 读取文件流

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

 

posted @ 2022-10-10 11:37  Mr_Xul  阅读(31)  评论(0)    收藏  举报