创建文件时不开/锁呢? [英] Create file without opening/locking it?
问题描述
有谁知道一个办法(相当简单)创建没有真正打开/锁定它的文件?在File类的方法创建文件始终返回一个FileStream。我想要做的就是创建一个文件,将其重命名(与File.Move),然后使用它。
Does anyone know of a way to (reasonably simple) create a file without actually opening/locking it? In File class, the methods for file creation always return a FileStream. What I want to do is to create a file, rename it (with File.Move) and then use it.
现在我有:
- 创建它
- 关闭
- 重命名
- 重新打开使用
推荐答案
也许你可以尝试使用文件。 WriteAllText方法(字符串,字符串) 与文件名和一个空字符串。
Maybe you can try using File.WriteAllText Method (String, String) with the file name and an empty string.
创建一个新的文件,写 指定的字符串的文件,然后 关闭该文件。如果目标文件 已经存在,将被覆盖。
Creates a new file, writes the specified string to the file, and then closes the file. If the target file already exists, it is overwritten.
这篇关于创建文件时不开/锁呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!