最简单的方式来读取和写入文件 [英] Easiest way to read from and write to files
本文介绍了最简单的方式来读取和写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在C#中有很多不同的方式来读取和写入文件(文本文件,而不是二进制文件)。
There are a lot of different ways to read and write files (text files, not binary) in C#.
我只需要一些容易的东西,并使用最少的代码,因为我将在我的项目中很多文档。我只需要一些 string
,因为我需要的是读写$ code> string s。
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 string
since all I need is to read and write string
s.
推荐答案
使用 File.ReadAllText 和 File.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);
这篇关于最简单的方式来读取和写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文