覆盖C#中的现有文件 [英] Overriding an existing file in C#
本文介绍了覆盖C#中的现有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
修订!
我想创建一个名为test.txt的文件.
I want to create a file say called test.txt.
如果该文件已经存在,我想创建一个名为test1.txt的文件,依此类推.
if that file already exists I want to create file called test1.txt and so on.
推荐答案
打开文件时,将 FileMode.Create
传递给 File.Open(string,FileMode)
它将每次创建一个新文件.
Pass in FileMode.Create
to File.Open(string, FileMode)
when opening the file and it will create a new file every time.
FileStream file = File.Open("text.txt", FileMode.Create);
这篇关于覆盖C#中的现有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文