开发工具 Visual Studio 2010
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace FileAccessTest
{
class Program
{
static void Main(string[] args)
{
WriteText("test content!");
System.Console.WriteLine(ReadText());
System.Console.ReadKey();
}
static void WriteText(string content)
{
StreamWriter sw = new StreamWriter("test.txt", false, Encoding.UTF8);
sw.WriteLine(content);
sw.Flush();
sw.Close();
}
static string ReadText()
{
StreamReader sr = new StreamReader("test.txt");
string content = sr.ReadToEnd();
sr.Close();
return content;
}
}
}
运行结果