我正在使用Binarywriter将blob数据(PDF)从oracle保存到磁盘。当我打开生成的文件时,结果很难看。我认为这是1个字符用一个字节写入的问题。
我如何才能增加到8。(/BitsPerComponent 8)
有什么想法吗?
long CurrentIndex = 0;
int BufferSize = 10000;
long BytesReturned;
byte[] Blob = new byte[BufferSize];
OracleDataReader reader = comando.ExecuteReader(CommandBehavior.SequentialAccess);
string filepath = "C:\\ttttt.pdf";
while (reader.Read())
{
FileStream fs = new FileStream(filepath, FileMode.OpenOrCreate, FileAccess.Write);
BinaryWriter writer = new BinaryWriter(fs);
//reset the index to the beginning of the file
CurrentIndex = 0;
BytesReturned = reader.GetBytes(0, CurrentIndex, Blob, 0, BufferSize);
while (BytesReturned == BufferSize)
{
writer.Write(Blob);
writer.Flush();
CurrentIndex += BufferSize;
BytesReturned = reader.GetBytes(0, CurrentIndex, Blob, 0, BufferSize);
}
writer.Write(Blob, 0, (int)BytesReturned);
writer.Flush();
writer.Close();
fs.Close();
}
1条答案
按热度按时间aor9mmx11#
您不需要使用BinaryWriter。直接写入数据流即可。BinaryWriter的预期使用案例是将基本资料类型写入数据流以进行序列化。
**更新:**自动从
Base64(MD5(Blob))
生成文件名.