覆盖选项文件给用户?
我需要在目录或路径中创建一个二进制文件,如果该文件存在,应用程序应询问用户是否要覆盖它。我有这段代码来写入文件,那么,如何验证文件是否存在并显示控制台消息?
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]);
}
}
}
谢谢..
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..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
File.Exists(binaryFilePath)
应该对您有帮助。File.Exists(binaryFilePath)
should help you.您可以尝试这样的操作:
其中
PromptUser()
将询问用户是否要覆盖该文件You could try something like this:
Where
PromptUser()
will ask the user if they want to override the file