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-05-08 11:25:55 发布