有很多不同的方式来读取和写入文件(文本文件,不是二进制)在 C# 中。
我只需要简单且使用最少代码的东西,因为我将在项目中大量使用文件。我只需要一些东西string
因为我需要的只是阅读和写作string
s.
Use 文件.ReadAllText and 文件.WriteAllText.
MSDN 示例摘录:
// Create a file to write to.
string createText = "Hello and Welcome" + Environment.NewLine;
File.WriteAllText(path, createText);
...
// Open the file to read from.
string readText = File.ReadAllText(path);
这一页列出了常见 I/O 任务的各种帮助器方法。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)