http://msdn.microsoft.com/en-us/library/system.io.file(v=vs.110).aspx
using System; using System.IO; class Test { public static void Main() { string path = @"c:\temp\MyTest.txt"; if (!File.Exists(path)) { // Create a file to write to. using (StreamWriter sw = File.CreateText(path)) { sw.WriteLine("Hello"); sw.WriteLine("And"); sw.WriteLine("Welcome"); } } // Open the file to read from. using (StreamReader sr = File.OpenText(path)) { string s = ""; while ((s = sr.ReadLine()) != null) { Console.WriteLine(s); } } } }
本文介绍了一个使用C#进行文件读写的简单示例。示例中首先创建了一个名为“MyTest.txt”的文本文件,并向其中写入了三行文本。接着,程序打开该文件并逐行读取内容,最后将内容输出到控制台。
1138

被折叠的 条评论
为什么被折叠?



