FILESTREAM与DeleteOnClose文件选项选项、文件、FILESTREAM、DeleteOnClose

2023-09-03 13:07:10 作者:朕要上房揭瓦

在我的项目,我必须创建一个USB设备的一些临时文件,我想删除闭幕。所以我用了code像

In my project I have to create some temp files in an USB device, which I want to delete on Closing. So I used a code like

this.fcommandHandler = new FileStream(TempFileName,
FileMode.CreateNew, FileAccess.ReadWrite,
FileShare.ReadWrite, 512, FileOptions.DeleteOnClose);

它工作正常。但问题是,我想用一个更FileOption,如无缓冲。

It works fine. But the problem is I want to use one more FileOption, like No buffering.

private const FileOptions FILE_FLAG_NO_BUFFERING = (FileOptions)0x20000000;

this.fcommandHandler = new FileStream(TempFileName,
FileMode.CreateNew, FileAccess.ReadWrite,
FileShare.ReadWrite, 512, FileOptions.DeleteOnClose & FILE_FLAG_NO_BUFFERING);

但它不是删除文件后闭幕。请大家帮帮忙。

But its not deleting the File after closing. Please help.

推荐答案

您需要使用|而不是和放大器;

You need to use | instead of &.

这些都是二进制的标志,而当你说和放大器;,您可以有效地掩盖他们都走了,导致没有选择可言。

These are binary flags, and when you say &, you effectively mask them all away, resulting in no options at all.