public byte[] fileTobyte(string filePath)
{
byte[] buffer;
using (FileStream fs = File.OpenRead(filePath))
{
buffer = new byte[fs.Length];
byte[] b = new byte[1024];
//UTF8Encoding temp = new UTF8Encoding(true);
int i = 0;
while (fs.Read(b, 0, b.Length) > 0)
{
for (int j = 0; j < 1024; j++)
{
if (i * 1024 + j < buffer.Length)
{
buffer[i * 1024 + j] = b[j];
}
}
i++;
}
fs.Close();
fs.Dispose();
}
return buffer;
}C# 文件转字节数组 byte[]
最新推荐文章于 2024-06-05 23:18:20 发布
本文介绍了一种将文件转换为字节数组的方法。通过使用FileStream读取指定路径下的文件,并将其内容逐块读入到字节数组中。此方法适用于需要将文件内容作为字节数据进行处理或传输的场景。
608

被折叠的 条评论
为什么被折叠?



