在 C# 中读取任何类型的文件

Reading any type of file in C#

我的程序需要从给定的目录路径读取任何类型的文件,并且必须将该信息写入字节数组。

 string combine = Path.Combine(precombine, filename);
 string content = System.IO.File.ReadAllText(combine);

这样我可以读取文本文件,但是我必须读取所有类型的文件,例如音乐或图像,并将它们写入字节数组。

使用File.ReadAllBytes方法

byte[] fileContent = System.IO.File.ReadAllBytes(combine);