如何将Byte [] buf写入文件而不将其转换为字符串?
public Int32 OnWriteData(Byte[] buf, Int32 size, Int32 nmemb, Object extraData)
{
SockBuff = SockBuff + System.Text.Encoding.UTF8.GetString(buf);
return size * nmemb;
}
现在想找几个小时工作的东西。
答案 0 :(得分:2)
System.IO.File.WriteAllBytes
答案 1 :(得分:1)
如果您只想要一个只包含字节缓冲区的文件,请使用上面的答案,如果您想对一个文件执行多个字节缓冲区写入,我会像这样写字节:
using (StreamWriter myStreamWriter = new StreamWriter(filePath))
{
// Some logic or something, who knows
myStreamWriter.BaseStream.Write(byteBuffer1, 0, byteBuffer1.Length);
// Some logic or something, who knows
myStreamWriter.BaseStream.Write(byteBuffer2, 0, byteBuffer2.Length);
}