.NET GZipStream,以及磁盘空间不足异常

发布于 2024-08-20 12:03:50 字数 1193 浏览 1 评论 0原文

我正在使用以下代码写入每次创建新的压缩文件。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

破晓 2024-08-27 12:03:50

如果已达到分配给用户的磁盘配额,则会出现此消息。

管理员可以通过右键单击“我的电脑”中的磁盘,选择“属性”,然后使用“配额”选项卡来设置每用户配额。

验证配额是否已禁用,或者运行您的应用程序的用户是否有足够的配额。

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.

千と千尋 2024-08-27 12:03:50

将 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文