FileStream 可以从只读提升为读写吗?
有没有办法将只读文件流提升为读写?我正在寻找类似于 Win32 SDK 函数 ReOpenFile 的功能。
Is there a way to promoting a Read-Only FileStream to Read-Write? I am looking for functionality similar to the Win32 SDK function ReOpenFile.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
干得好。使用了一点 pInvoke Interop 的优点(缺点),但它可以做到。我为访问和共享模式参数省略并添加了一些神奇的常量,因此请随意封装它们。
Here you go. Uses a bit of pInvoke Interop goodness (badness), but it'll do it. I've skimped and threw in some magic constants for the access and sharemode parameters, so feel free to encapsulate that.
你不能。
为什么首先要以只读方式打开它?为什么不直接打开一个新的文件流呢?如果 FileShare 设置正确,您甚至不必关闭旧的共享。
You can't.
Why do you open it readonly in the first place? Why don't you just open a new FileStream? You do not even have to close the old one, provided that the FileShare is set correctly.