关于 FileStream Write方法的一个小坑

Dim bytes As Byte() = Dt.Rows(0)("img")
Dim destFilePath As String = Path.GetTempPath & Dt.Rows(0)("file_name").ToString.Trim
If Dt.Rows(0)("file_name").ToString.Trim = "" Then
destFilePath = Path.GetTempFileName & Dt.Rows(0)("file_type").ToString.Trim
End If
Dim pFileStream As FileStream = New FileStream(destFilePath, FileMode.Create, FileAccess.ReadWrite)
pFileStream.Write(bytes, 0, bytes.Length - 1) ‘这里一定要减1,不然文件后面会多一个字节,如果是excel文件打开会提示修复!
pFileStream.Close()
System.Diagnostics.Process.Start(destFilePath)

posted @ 2020-03-28 11:11  GavinLuo  阅读(862)  评论(0编辑  收藏  举报