如何允许其他程序读取文件,同时使用 fopen 和 fwrite 写入文件?
How to allow other programs to read file, while writing to it using fopen and fwrite?
我正在为正在创建的视频打开一个文件,并使用 C++ 中的 fopen 写入磁盘,我能够写入磁盘。但是当我在写它的时候尝试读取它时,它会抛出错误,说它没有权限读取文件,一旦我关闭文件或停止程序,我突然可以从中读取。
没写完没问题,写的好像我崩溃了程序一样,还能读。另外,VLC 的日志告诉我这是一个权限问题。
知道如何更改该权限吗?
回复 William 要求提供代码片段或打开是否发生在文件存在之前:
Thanks William, here's what I've got. I waited a few minutes and could see the file with windows explorer by that point and waited until after I'd flushed and data was there, couldn't open with VLC or Notepad++ or Notepad or Windows Media Player
Notepad says cannot access because it is being used by another process, others too.
Here is the VLC log while it tries to open this:
http://snippi.com/s/g4cbu23
Here is where I create the file with fopen:
http://snippi.com/s/cyajw4h
At the very end is where I write to the file using fwrite and flush:
http://snippi.com/s/oz27m0g
如果您希望文件可共享,您需要将 _fsopen
与 _SH_DENYNO
结合使用。
我正在为正在创建的视频打开一个文件,并使用 C++ 中的 fopen 写入磁盘,我能够写入磁盘。但是当我在写它的时候尝试读取它时,它会抛出错误,说它没有权限读取文件,一旦我关闭文件或停止程序,我突然可以从中读取。
没写完没问题,写的好像我崩溃了程序一样,还能读。另外,VLC 的日志告诉我这是一个权限问题。
知道如何更改该权限吗?
回复 William 要求提供代码片段或打开是否发生在文件存在之前:
Thanks William, here's what I've got. I waited a few minutes and could see the file with windows explorer by that point and waited until after I'd flushed and data was there, couldn't open with VLC or Notepad++ or Notepad or Windows Media Player
Notepad says cannot access because it is being used by another process, others too.
Here is the VLC log while it tries to open this:
http://snippi.com/s/g4cbu23
Here is where I create the file with fopen:
http://snippi.com/s/cyajw4h
At the very end is where I write to the file using fwrite and flush:
http://snippi.com/s/oz27m0g
如果您希望文件可共享,您需要将 _fsopen
与 _SH_DENYNO
结合使用。