有很多不同的方法来读取和写入在C#中的文件(文本文件不是二进制)。
There are a lot of different ways to read and write files (Text Files not Binary) in C#.
我只需要一些简单,使用最少量的code,因为我将要使用的文件在我的项目的工作很多。我只需要一些弦乐,因为我需要的是读取和写入字符串。
I just need something that is easy and uses the least amount of code, because I am going to be working with files a lot in my project. I only need something for Strings since all I need is to read and write Strings.
File.ReadAllText
File.WriteAllText
简单得不能再简单...
Could not be simpler...
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);