.NET GZipStream,以及磁盘空间不足异常
我正在使用以下代码写入每次创建新的压缩文件。
using (FileStream fs = File.Open(sortOrderFileName, FileMode.Create,FileAccess.Write, FileShare.ReadWrite))
using (System.IO.Compression.GZipStream gzip = new System.IO.Compression.GZipStream(fs, System.IO.Compression.CompressionMode.Compress))
using (StreamWriter sw = new StreamWriter(gzip))
{
// use the streamwriter sw to write to the stream
}
但是,当我运行此命令时,我收到 IOException 并显示消息“磁盘空间不足”。但是,我正在写入文件的驱动器上有 19GB 的可用空间。
根据 GZipStream 的文档,它不能用于写入大于 4GB 的文件。然而,到目前为止写入的文件大小只有250MB。
这是异常:
类型:System.IO.IOException 异常消息:磁盘空间不足。
内部异常: StackTrace:位于 System.IO.__Error.WinIOError(Int32 errorCode,String MaybeFullPath) 在 System.IO.FileStream.WriteCore(Byte[] 缓冲区,Int32 偏移量,Int32 计数) 在 System.IO.FileStream.FlushWrite(布尔称为FromFinalizer) 在 System.IO.FileStream.Dispose(布尔处置) 在 System.IO.Stream.Close() 在 System.IO.Compression.DeflateStream.Dispose(布尔处置) 在 System.IO.Stream.Close() 在 System.IO.Compression.GZipStream.Dispose(布尔处置) 在 System.IO.Stream.Close() 在 System.IO.StreamWriter.Dispose(布尔处置) at System.IO.StreamWriter.Close()
另外,这不是网络文件。
有什么想法我在这里做错了吗?
I am using the following code to write to a compressed file that I create new everytime.
using (FileStream fs = File.Open(sortOrderFileName, FileMode.Create,FileAccess.Write, FileShare.ReadWrite))
using (System.IO.Compression.GZipStream gzip = new System.IO.Compression.GZipStream(fs, System.IO.Compression.CompressionMode.Compress))
using (StreamWriter sw = new StreamWriter(gzip))
{
// use the streamwriter sw to write to the stream
}
However, when I run this, I am getting an IOException with the message "Out of disk space". However, there is 19GB of space available on the drive on which I am writing the file.
According to the docs for GZipStream, it cannot be used to write a file greater than 4GB. However, the file written till now is only 250MB in size.
Here is the exception:
Type: System.IO.IOException
Exception Msg: There is not enough space on the disk.
Inner Exception:
StackTrace: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.WriteCore(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.FileStream.FlushWrite(Boolean calledFromFinalizer)
at System.IO.FileStream.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at System.IO.Compression.DeflateStream.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at System.IO.Compression.GZipStream.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at System.IO.StreamWriter.Dispose(Boolean disposing)
at System.IO.StreamWriter.Close()
Also, this is not a network file.
Any ideas what I am doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果已达到分配给用户的磁盘配额,则会出现此消息。
管理员可以通过右键单击“我的电脑”中的磁盘,选择“属性”,然后使用“配额”选项卡来设置每用户配额。
验证配额是否已禁用,或者运行您的应用程序的用户是否有足够的配额。
This message can appear if the disk quota assigned to the user has been reached.
An administrator can set the per-user quota by right-clicking on the disk in My Computer, choosing Properties, and using the Quota tab.
Verify that quotas are disabled or that the user your application is running as has sufficient quota.
将 FileShare 模式更改为独占,看看是否有影响,我不明白为什么 FileShare 设置为读/写?对此的任何解释,在压缩时,该文件应该是 gzip 独有的才能正常工作...
希望这有帮助,
此致,
汤姆.
Change the FileShare mode to exclusive to see if that makes a difference, I don't understand why the FileShare is set to Read/Write? Any explanation for that, when compressing, the file should be exclusive for the gzip to work properly...
Hope this helps,
Best regards,
Tom.