有各种方法将文本附加到文件,虽然我想知道是否知道最短的方法来做到这一点
例如,在现有的txt文件中添加一个新行:
line1
line2
<new-line-here>
Run Code Online (Sandbox Code Playgroud)
dri*_*iis 11
这将是这样的:
File.AppendAllText("c:\filepath.txt", "text to append");
Run Code Online (Sandbox Code Playgroud)
有关详细信息,请参见File.AppendAllText.该文件类有很多做普通的文件操作有用的静态方法.
File类的静态方法使其非常简单:
File.AppendAllLines("filename.txt", new string[] { "text to append" });
Run Code Online (Sandbox Code Playgroud)
编辑:使用数组略短.
| 归档时间: |
|
| 查看次数: |
7914 次 |
| 最近记录: |