码迷,mamicode.com
首页 > Windows程序 > 详细

C#读文件操作

时间:2015-06-09 11:49:27      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:

using System;
using System.IO;

namespace IO操作
{
    class Program
    {
        private const string FILE_NAME="IO.txt";
        static void Main(string[] args)
        {
            if (!File.Exists(FILE_NAME))
            {
                Console.WriteLine("{0}does not exists!",FILE_NAME);
                Console.ReadLine();
                return;
            }
            //方法一:
            //FileStream FS = new FileStream(FILE_NAME, FileMode.Open, FileAccess.Read);
            //BinaryReader BR = new BinaryReader(FS);
            //for (int i = 0; i < 1; i++)
            //{
            //    Console.WriteLine(BR.ReadString());
            //}
            //BR.Close();
            //FS.Close();
            //Console.ReadLine();

            //方法一:
            using (StreamReader SR = File.OpenText(FILE_NAME))
            {
                string input;
                while ((input = SR.ReadLine()) != null)
                {
                    Console.WriteLine(input);
                }
                Console.WriteLine("The end of the txt");
                Console.ReadLine();
                SR.Close();
            }
        }
    }
}

C#读文件操作

标签:

原文地址:http://blog.csdn.net/lucky51222/article/details/46424313

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!