读写文件

作者:追风剑情 发布于:2014-8-3 13:52 分类:C#

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

标签: C#

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号