简体   繁体   English

将选项文件覆盖给用户?

[英]overwrite option file to user?

I need to create a binary file in a directory or path, if the file exists, the application should ask to the user if want to overwrite it. 我需要在目录或路径中创建一个二进制文件,如果该文件存在,则应用程序应询问用户是否要覆盖它。 I have this code to write the file, so, how can verify if the file exist and show to console the message? 我有这段代码可以编写文件,因此,如何验证文件是否存在并显示消息控制台?

using (FileStream fileStream = new FileStream(binaryFilePath, FileMode.Create)) // destiny file directory.
            {
                using (BinaryWriter binaryWriter = new BinaryWriter(fileStream))
                {
                    for (int i = 0; i < frameCodes.Count; i++)
                    {
                        binaryWriter.Write(frameCodes[i]);
                    }
                }
            }

thanks.. 谢谢..

File.Exists(binaryFilePath)应该可以为您提供帮助。

You could try something like this: 您可以尝试这样的事情:

if(File.Exists(binaryFilePath) && PromptUser())
{
...
}

Where PromptUser() will ask the user if they want to override the file PromptUser()会在哪里询问用户是否要覆盖文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM