【发布时间】:2020-04-14 16:24:28
【问题描述】:
我正在为我正在创建的视频打开一个文件,并使用 C++ 中的 fopen 写入磁盘,我可以写入磁盘。但是当我在写它的时候尝试读取它时,它会抛出错误,说它没有权限读取文件,只要我关闭文件或停止程序,我就可以突然读取它。
如果程序崩溃,没有完成写入不是问题,仍然可以读取它。此外,VLC 的日志告诉我这是权限问题。
知道如何更改该权限吗?
回复 William 询问代码 sn-ps 或是否在文件存在之前打开:
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
【问题讨论】:
-
没有读取文件的权限,或者没有打开文件的权限?显示一些代码。
fopen应该会成功。如果您尝试使用 VLC 等大型设备读取文件,则很可能在文件存在之前打开,您看到的错误基本上是由于缓存无效。 -
谢谢威廉,这就是我所拥有的。我等了几分钟,到那时可以用 Windows 资源管理器看到该文件,然后等到我刷新并且数据在那里之后,无法使用 VLC 或 Notepad++ 或记事本或 Windows Media Player 打开记事本说无法访问,因为它是被另一个进程使用,其他进程也被使用。这是 VLC 日志,它试图打开它:snippi.com/s/g4cbu23 这是我用 fopen 创建文件的地方:snippi.com/s/cyajw4h 最后是我使用 fwrite 和刷新写入文件的地方:snippi.com/s/oz27m0g
-
这能回答你的问题吗? C++ : Opening a file in non exclusive mode