鸟语天空
读写文件
post by:追风剑情 2014-8-3 13:52

开发工具 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;
        }
    }
}

运行结果

读写文件.png

评论:
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容